I have a reference raster and a stack of other rasters. I wanted to perform Mean, Std Dev and Bias of the reference with respect to the remaining. So I calculated the Cell Stats of all but when I try to save it in a csv its shows me columns more than the number of stack rasters.The no of rows is the exeact number of columns while the in the next column it doubles up and so on. The values of mean and all is a num while in the stack rasters its shows as named num. enter image description here

The code is as shown:

r1 <- raster("Ref.tif")
mn<-cellStats(r1, stat='mean', na.rm=TRUE, asSample=TRUE)
 sdev<-cellStats(r1, stat='sd', na.rm=TRUE, asSample=TRUE)
lt <- list.files(pattern = "\\.tif$")
st <- stack(lt)
mn1<-as.numeric(cellStats(st, stat='mean', na.rm=TRUE, asSample=TRUE))
sdev1<-as.numeric(cellStats(st, stat='sd', na.rm=TRUE, asSample=TRUE))
tab <- table(min_V1,max_V1, bias_mn, bias_mn2) 
write.csv(tab, file="Out.csv")
  • Your table call is tabulating all your data so you ar egetting a frequency count of the occurrences of each set of values. Did you really mean to make a data frame instead of a table? – Spacedman Jun 8 '18 at 7:18
  • I just want to export it in a csv. I am not so familiar with a data frame – ARU Jun 8 '18 at 7:21
  • Do you know what table does? Why did you use it here? – Spacedman Jun 8 '18 at 7:24
  • Oh yes, Sir, I went through data frame and it does exactly what I wanted. Thank you, Sir. – ARU Jun 8 '18 at 7:30
  • Can you add it as an answer? – ARU Jun 8 '18 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.