How do I subset a
SpatRaster from the R
terra package by value? This is the raster:
> rh10 class : SpatRaster dimensions : 2732, 4379, 1 (nrow, ncol, nlyr) resolution : 1000, 1000 (x, y) extent : -1950750, 2428250, -1785500, 946500 (xmin, xmax, ymin, ymax) coord. ref. : +proj=lcc +lat_0=42.5 +lon_0=-100 +lat_1=25 +lat_2=60 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs source : memory name : vp_1 min value : 0.096915 max value : 1.291845 time : 2009-01-01 12:00:00 > typeof(rh10)  "S4"
The raster has relative humidity values in the cells. I inspected the raster.
> summary(rh10) vp_1 Min. :0.106 1st Qu.:0.513 Median :0.594 Mean :0.581 3rd Qu.:0.678 Max. :1.283 NA's :22329 Warning message: [summary] used a sample
Because it's supposed to be relative humidity, I was expecting values less than 1. I guess greater than 1 is possible, but I'm trying to figure out which cells in the raster are over 1. I can't figure out how to subset the raster to begin with.
> length(rh10$vp_1 > 1.0)  1 > length(rh10 > 1.0)  1 > rh10[rh10> 1.0] Error in rh10[rh10 > 1] : object of type 'S4' is not subsettable
How should I go about figuring which are the uncommon cells? I'd like to see how many there are and where specifically they occur in the raster? Even my idea of subsetting is not correct, I'd like to know how I should properly subset the raster by cell values in addition to answering the related questions of how many and where.