Thanks for all the responses @raytong. Really appreciate your help.
Just a couple of questions for the solution you provided @raytong :
Is -3:1... referring to the range of my values (which are -Inf:Inf)?
And am I right to assume that res is just the name you gave the to final output array that I need? Or is it a function?
I tried fashioning my own code because I have the impulsive need to make things difficult for myself. Could you kindly tell me what I'm doing wrong?
mydata[is.na(mydata)] <- "NA" #Not every grid cell has a value. Some of them are NA that I'd like to ignore.
classified<-array(data=NA, dim=c(720,360,349)) #empty array to classify original data into the fruit categories
for (i in 1:720){
for (j in 1:360){
for (k in 1:349){
if (mydata[i,j,k]>1){
classified[i,j,k]=="irrelevant"
}
else{
if(mydata[i,j,k]>0 & mydata[i,j,k]<=1)
classified[i,j,k]=="peach"
}
else{
if(mydata[i,j,k]>-1.0 & mydata[i,j,k]<=0)
classified[i,j,k]=="pear"
}
else{
if(mydata[i,j,k]>-2.0 & mydata[i,j,k]<=-1.0)
classified[i,j,k]=="orange"
}
else{
if(mydata[i,j,k]<=-2.0)
classified[i,j,k]=="apple"
}
else{
classified[i,j,k]==NA
}
}
}
}
irrelevant<-array(data=NA,dim=c(720,360)) #empty arrays to count how many of each category there is in each grid cell for 349 sheets
peach<-array(data=NA,dim=c(720,360))
pear<-array(data=NA,dim=c(720,360))
orange<-array(data=NA,dim=c(720,360))
apple<-array(data=NA,dim=c(720,360))
for (i in 1:720){
for (j in 1:360){
irrelevant[i,j]<-length(which(classified[i,j,1:349]=="irrelevant"))
peach[i,j]<-length(which(classified[i,j,1:349]=="peach"))
pear[i,j]<-length(which(classified[i,j,1:349]=="pear"))
orange[i,j]<-length(which(classified[i,j,1:349]=="orange"))
apple[i,j]<-length(which(classified[i,j,1:349]=="apple"))
}
}
Thanks again!