我在Rstudio中运行此脚本时出现问题,我收到错误
TMX03_site [,24]中的错误:下标超出界限
我总共有5个脚本,就像这两个脚本工作正常,三个脚本会出现同样的错误。
我查看了与此问题相关的其他帖子,并尝试过这些建议,但尚未找到解决问题的方法。我希望那里有人可以为我拍摄这个问题,并找出我出错的地方。
非常感谢
setwd("G:/All ArcGIS/tmax03/03")
m03_1 <- raster("1320_setnull")
m03_2 <- raster("2320_setnull")
m03_3 <- raster("3320_setnull")
m03_4 <- raster("4320_setnull")
m03_5 <- raster("5320_setnull")
m03_6 <- raster("6320_setnull")
m03_7 <- raster("7320_setnull")
m03_8 <- raster("8320_setnull")
m03_9 <- raster("9320_setnull")
m03_10 <- raster("10320_setnull")
m03_11 <- raster("11320_setnull")
m03_12 <- raster("12320_setnull")
m03_13 <- raster("1380_setnull")
m03_14 <- raster("2380_setnull")
m03_15 <- raster("3380_setnull")
m03_16 <- raster("4380_setnull")
m03_17 <- raster("5380_setnull")
m03_18 <- raster("6380_setnull")
m03_19 <- raster("7380_setnull")
m03_20 <- raster("8380_setnull")
m03_21 <- raster("9380_setnull")
m03_22 <- raster("10380_setnull")
m03_23 <- raster("11380_setnull")
m03_24 <- raster("12380_setnull")
m03.stacked<-stack(m03_1,m03_2,m03_3,m03_4,m03_5,m03_6,m03_7,m03_8,m03_10,
m03_11,m03_12,m03_13,m03_14,m03_15,m03_16,m03_17,m03_18,m03_19,m03_20,
m03_21,m03_22,m03_23,m03_24)
writeRaster(m03.stacked, "m03.stacked.nc",overwrite=TRUE)
write03 <- 'm03.stacked.nc' # link to nc
site_03 <- read.csv("C:/Users/Vaughn/Desktop/suteri/tmax/sites_03.csv")
for (x in 1:nrow(site_03)) {
longlat <- c(site_03[x,1],site_03[x,2])
}
#convert to a matrix and transpose by
site_03 <- t(matrix(longlat))
TMX03 <- brick(write03)
TMX03_site <- extract(TMX03, site_03)
TMX03_site1 <- TMX03_site[, 1]
TMX03_site2 <- TMX03_site[, 2]
TMX03_site3 <- TMX03_site[, 3]
TMX03_site4 <- TMX03_site[, 4]
TMX03_site5 <- TMX03_site[, 5]
TMX03_site6 <- TMX03_site[, 6]
TMX03_site7 <- TMX03_site[, 7]
TMX03_site8 <- TMX03_site[, 8]
TMX03_site9 <- TMX03_site[, 9]
TMX03_site10 <- TMX03_site[, 10]
TMX03_site11 <- TMX03_site[, 11]
TMX03_site12 <- TMX03_site[, 12]
TMX03_site13 <- TMX03_site[, 13]
TMX03_site14 <- TMX03_site[, 14]
TMX03_site15 <- TMX03_site[, 15]
TMX03_site16 <- TMX03_site[, 16]
TMX03_site17 <- TMX03_site[, 17]
TMX03_site18 <- TMX03_site[, 18]
TMX03_site19 <- TMX03_site[, 19]
TMX03_site20 <- TMX03_site[, 20]
TMX03_site21 <- TMX03_site[, 21]
TMX03_site22 <- TMX03_site[, 22]
TMX03_site23 <- TMX03_site[, 23]
TMX03_site24 <- TMX03_site[, 24]
> str(TMX03)
Formal class 'RasterBrick' [package "raster"] with 12 slots
..@ file :Formal class '.RasterFile' [package "raster"] with 13 slots
.. .. ..@ name : chr "G:\\All ArcGIS\\tmax03\\03\\m03.stacked.nc"
.. .. ..@ datanotation: chr "FLT4S"
.. .. ..@ byteorder : chr "little"
.. .. ..@ nodatavalue : num -3.4e+38
.. .. ..@ NAchanged : logi FALSE
.. .. ..@ nbands : int 23
.. .. ..@ bandorder : chr "BIL"
.. .. ..@ offset : int 0
.. .. ..@ toptobottom : logi FALSE
.. .. ..@ blockrows : int 0
.. .. ..@ blockcols : int 0
.. .. ..@ driver : chr "netcdf"
.. .. ..@ open : logi FALSE
..@ data :Formal class '.MultipleRasterData' [package "raster"] with 14
.. .. ..@ values : logi[0 , 0 ] slots
.. .. ..@ offset : num 0
.. .. ..@ gain : num 1
.. .. ..@ inmemory : logi FALSE
.. .. ..@ fromdisk : logi TRUE
.. .. ..@ nlayers : int 23
.. .. ..@ dropped : NULL
.. .. ..@ isfactor : logi FALSE
.. .. ..@ attributes: list()
.. .. ..@ haveminmax: logi FALSE
.. .. ..@ min : num [1:23] Inf Inf Inf Inf Inf ...
.. .. ..@ max : num [1:23] -Inf -Inf -Inf -Inf -Inf ...
.. .. ..@ unit : chr ""
.. .. ..@ names : chr [1:23] "X1" "X2" "X3" "X4" ...
..@ legend :Formal class '.RasterLegend' [package "raster"] with 5 slots
.. .. ..@ type : chr(0)
.. .. ..@ values : logi(0)
.. .. ..@ color : logi(0)
.. .. ..@ names : logi(0)
.. .. ..@ colortable: logi(0)
..@ title : chr "variable"
..@ extent :Formal class 'Extent' [package "raster"] with 4 slots
.. .. ..@ xmin: num 1903933
.. .. ..@ xmax: num 3021933
.. .. ..@ ymin: num 5305094
.. .. ..@ ymax: num 6757094
..@ rotated : logi FALSE
..@ rotation:Formal class '.Rotation' [package "raster"] with 2 slots
.. .. ..@ geotrans: num(0)
.. .. ..@ transfun:function ()
..@ ncols : int 1118
..@ nrows : int 1452
..@ crs :Formal class 'CRS' [package "sp"] with 1 slot
.. .. ..@ projargs: chr NA
..@ history : list()
..@ z :List of 1
.. ..$ unknown: int [1:23(1d)] 1 2 3 4 5 6 7 8 9 10 ...
加载的包是raster和sp