I am working with time series of rasters and I need to analyse a ts of 17 dates. For each date, I imported band 5 and band 7. I made a list of the 17 bands-5 and a list of the 17 bands-7, called respectively list_B5 and list_B7. I would like to stack together bands of the same date, so: the first raster of list_B5 with the first raster of list_B7; the second raster of list_B5 with the second raster of list_B7; and so on.
I am new to loops, but I tried to write one:
for (i in seq_along(length(list_B5)) [1]) {
for (j in seq_along(length(list_B7)) [2]) {
B5 <- raster(list_B5[[i]]) #extract the raster of interest
B7 <- raster(list_B7[[j]]) #extract the raster of interest
test[i,j] <- brick(B5, B7) #stack them together
}
}
with "test" being:
test <- brick(nrows=5490, ncol=5490, nl=17)
Unfortunately I get the following error:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘raster’ for signature ‘"NULL"’
I do not understand why it doesn't accept the lines in which I try to extract the raster of interest, since this line alone usually works:
> raster(list_B5[[3]])
class : RasterLayer
dimensions : 5490, 5490, 30140100 (nrow, ncol, ncell)
resolution : 20, 20 (x, y)
extent : 6e+05, 709800, 5590200, 5700000 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=31 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
Can someone explain to me why I get the above mentioned error?
i
andj
? Also, why do you usei
with[1]
andj
with[2]
? I recommend you detelej
loop and use onlyi
. Iftest
is a list, usetest[[i]] <- brick(B5, B7)
– aldo_tapia