I have a multi-band (20 layers) raster loaded into R as a RasterBrick using brick()
.
My plan is to normalize each band from 0 to 1 using the approach that was proposed in this thread: https://stats.stackexchange.com/questions/70801/how-to-normalize-data-to-0-1-range
Here some sample code to visualize my problem:
for(j in 1:nlayers(tif)){
min <- cellStats(tif[[j]],'min')
max <- cellStats(tif[[j]],'max')
for(i in 1:ncell(tif)){
tif[i][j] <- (tif[i][j]-min)/(max-min)
}
}
"tif" contains the raster brick. "j" is the current layer of "tif", while "i" is the current cell of layer[[i]]. I think the rest is pretty straight forward. The problem now is that it takes hours without finishing to replace a single value in a specific band. Why is it taking so long without finishing?
Cheers, Kai