#ncfile 读出是一个多维矩阵,你用temp[1:4]当然只会读出4笔 以下供参
#你可以针对每一次 (1:4)都画一次,在这里我不确定你要的操作,我取平均
#OB
library(ncdf4)
#library(magrittr)
#library(lubridate)
#library(units)
infile <- "D:/Env/air/air.2m.mon.mean.nc"
nx0 <- nc_open(infile)
print(nx0)
air <- ncvar_get(nx0, "air")
latx0<- ncvar_get(nx0, "lat")
lngx0<- ncvar_get(nx0, "lon")
#time<- ncvar_get(nx0, "time")
#tattr <- ncatt_get(nx0, "time") #get attributes
#units(time) <- make_unit(tattr$units)
#datex<- as.POSIXct(time) %>% as.Date(origin="1800-01-01 00:00") #:0.0")
#lvl <- ncvar_get(nx0, "level")
mair <- apply(air[,,1:4],c(1,2),function(x) mean(x-273.15, na.rm=T))
zt=matrix(mair,ncol=length(latx0),nrow=length(lngx0),byrow=F)
image(x=lngx0-180,y=rev(latx0),z=zt[,ncol(zt):1],
col = colorRamps::blue2red(128)) #rainbow(128)[50:128])
※ 引述《AndrewShi (没有妳的我)》之铭言:
: ※ 引述《AndrewShi (没有妳的我)》之铭言:
: : [问题类型]:
: : 程式咨询(我想用R 做某件事情,但是我不知道要怎么用R 写出来)
: : [软件熟悉度]:
: : 入门(写过其他程式,只是对语法不熟悉)
: : [问题叙述]:
: : 这是一个全球温度的资料(nc档),时间总共有467笔,我想利用R画出前4笔的全球温度图
: : ,所以 写了一个简单的while循环,但到了要image的时候就跑出了这个error,所以想请问大大
: : 们这个error是什么意思,以及我该如何解决??谢谢~
: : [程式范例]:
: : https://i.imgur.com/JlqAFxw.jpg
: : https://i.imgur.com/fLzCmiC.jpg
: 以下为资料来源与程式码:
: 资料来源:
: https://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanalysis2.pressure.html
: Air Temperature - Monthly Mean - 按图示