作者AndrewShi (没有你的我)
看板R_Language
标题Re: [问题] dimensions of z are not length(x)(-1)
时间Mon May 14 22:56:52 2018
※ 引述《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 - 按图示 -->里面的最後一笔资料
程式码:
rm(list=ls())
library(ncdf4)
air.nc<-nc_open("C:\\Users\\TOM\\Desktop\\R(资料库)\\air.2m.mon.mean.nc")
air.nc
"file C:\\Users\\TOM\\Desktop\\R(资料库)\\air.2m.mon.mean.nc has 5
dimensions:"
"lon Size:144"
"lat Size:73"
"level Size:17"
"nbnds Size:2"
"time Size:467"
"file C:\\Users\\TOM\\Desktop\\R(资料库)\\air.2m.mon.mean.nc has 2 variables"
"short air[lon,lat,level,time] Longname:Air temperature Missval:-32767"
"short head[level,time] Longname:Missing Missval:NA"
temp.nc<-nc_open("C:\\Users\\TOM\\Desktop\\R(资料库)\\air.2m.mon.mean.nc")
temp<-ncvar_get(temp.nc,"air")
temp[temp=="-32767"]<-NA
temp.nc$dim$lon$vals -> lon
temp.nc$dim$lat$vals -> lat
temp.nc$dim$level$vals -> lev
temp.nc$dim$nbnds$vals -> nbnds
temp.nc$dim$time$vals -> time
lat<-rev(lat)
i<-1
while(i<5){
print(temp[i])
i<-i+1
}
time="i"<-temp[i]
lon<-lon-180
temp<-(time="i")
temp<-matrix(c("i"=1:4))
image(lon,lat,matrix(temp,ncol=length(lat),nrow=length(lon),byrow=F))
library(sp)
library(maptools)
gpclibPermit()
data(wrld_simpl)
plot(wrld_simpl,add=TRUE)
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 150.117.35.12
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1526309815.A.F20.html