我目前正在尝试修改变量的层数。该变量称为“ Model4”,是一个矩阵。目前有95层。但是,我想创建一个新的Model4(假设为“ NewModel4”),其中有90层而不是95层。因此,我们的想法是仅使用前90个图层来将Model4的图层编号设置为90。
我已经尝试了以下操作:
new.data<-dplyr::between(Model4,0,89)
产生此错误:
Error: Not compatible with requested type: [type=S4; target=double].
然后我尝试了这个:
newfile<-Model4[Model4$onedaymax %in% (0:89),]
但是我收到此错误:
Error in .local(x, ...) : invalid layer names
然后我尝试了这个:
NewModel4 <- Model4[0:89,]
在此过程中,NewModel4的长度为8550!
来自dput(Model4):
file = new(".RasterFile"
, datanotation = "FLT4S"
, byteorder = "little"
, nodatavalue = -Inf
, NAchanged = FALSE
, nbands = 95L
, bandorder = "BIL"
, offset = 0L
, toptobottom = TRUE
, blockrows = 0L
, blockcols = 0L
, driver = "netcdf"
, open = FALSE
)
, data = new(".MultipleRasterData"
, values = structure(logical(0), .Dim = c(0L, 0L))
, offset = 0
, gain = 1
, inmemory = FALSE
, fromdisk = TRUE
, nlayers = 95L
, dropped = NULL
, isfactor = FALSE
, attributes = list()
, haveminmax = FALSE
, min = c(Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf,
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf,
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf,
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf,
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf,
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf,
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf,
Inf, Inf, Inf, Inf, Inf)
, max = c(-Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf,
-Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf,
-Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf,
-Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf,
-Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf,
-Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf,
-Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf,
-Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf,
-Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf)
, unit = "mm/day"
, names = c("X1", "X2", "X3", "X4", "X5", "X6", "X7", "X8", "X9", "X10",
"X11", "X12", "X13", "X14", "X15", "X16", "X17", "X18", "X19",
"X20", "X21", "X22", "X23", "X24", "X25", "X26", "X27", "X28",
"X29", "X30", "X31", "X32", "X33", "X34", "X35", "X36", "X37",
"X38", "X39", "X40", "X41", "X42", "X43", "X44", "X45", "X46",
"X47", "X48", "X49", "X50", "X51", "X52", "X53", "X54", "X55",
"X56", "X57", "X58", "X59", "X60", "X61", "X62", "X63", "X64",
"X65", "X66", "X67", "X68", "X69", "X70", "X71", "X72", "X73",
"X74", "X75", "X76", "X77", "X78", "X79", "X80", "X81", "X82",
"X83", "X84", "X85", "X86", "X87", "X88", "X89", "X90", "X91",
"X92", "X93", "X94", "X95")
)
, legend = new(".RasterLegend"
, type = character(0)
, values = logical(0)
, color = logical(0)
, names = logical(0)
, colortable = logical(0)
)
, title = "onedaymax"
, extent = new("Extent"
, xmin = -181.40625
, xmax = 178.59375
, ymin = -89.258464857103
, ymax = 89.258464857103
)
, rotated = FALSE
, rotation = new(".Rotation"
, geotrans = numeric(0)
, transfun = function ()
NULL
)
, ncols = 128L
, nrows = 64L
, crs = new("CRS"
, projargs = "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"
)
, history = list()
, z = list(1:95)
有没有办法做到这一点?
谢谢,我们将不胜感激!