Skip to content

Using a mask

2 messages · Ned Horning, Roger Bivand

#
Is there an easy way to mask (or flag) data values in R so they do not 
get processed. I am using predict.randomForest on a satellite image and 
there are a lot (~30%) of pixels with a value of "0" that I'd prefer not 
to process with predict.randomForest to save time. I was thinking it 
might be possible to create a data frame with valid data for each line 
read from the input multi-band image and then reconstruct the line 
before writing it out but I think the overhead would be very high. At 
least using the brute force methods like rbind.

All the best,

Ned
#
On Fri, 27 Feb 2009, Ned Horning wrote:

            
It looks as though setting the values to NA will work. In the 
predict.randomForest example, do:

df <- iris[ind == 2,]
is.na(df[1:10, 1:2]) <- TRUE
predict(iris.rf, df)

So setting the 0 values to NA might get you the results you want, 
maintaining the relative order of the observations.

Roger