Get band number of maximum value per pixel for multiband raster in R?
I have a multiband raster stack and I want to find the band number of the maximum value for each pixel. For this, I have used the following code: #Set working directory setwd("E:/Red Panda/TIF") library(raster)
#Get the names of all the files with extension ".tif" of the folder files <- list.files("E:/Red Panda/TIF/", pattern='tif$', full.names=TRUE ) files Raster_stack <- stack(files) Raster_stack names(Raster_stack) plot(Raster_stack)
Identify pixel-wise band with max value
pixelMaxBand.ras <- whiches.max(Raster_stack)
But I found this type of error: Error in .local(x, ...) : you can use only use this function for an object with less than 10 layers
Generally, I have >10 raster layers for different land use and land cover but this “whiches.max” function works for layers less than 10. Can you please suggest me the appropriate code that can work for rasters >10? Thank you.
Hi @spariyar -- you probably should rise this issue at https://github.com/rspatial/raster/issues.
@Nowosad thank you so much.