[R-sig-Geo] subsetting terra::raster

Herr, Alexander (L&W, Black Mountain) A|ex@nder@Herr @end|ng |rom c@|ro@@u
Tue Jul 14 06:17:55 CEST 2020


Hi,

I am moving from raster to terra. I get an error when I adapt the following raster code:
require(raster)
set.seed(666)
 reps=10
 r <- raster( matrix(nrow=reps,ncol=reps, round(rnorm(reps^2),1)))
 extent(r)<- c(1,101,1,101)
plot(r) 
xy<-xyFromCell(r,r[r>0])
z<-r[r>0]
cbind(xy,z)

Under terra code:
require(terra)
r <- rast( matrix(nrow=reps,ncol=reps, round(rnorm(reps^2),1)))
plot(r)
xy<-xyFromCell(r,r[r>0])
Error in r[r > 0] : object of type 'S4' is not subsettable

What am I doing wrong?

Thanks
herry


 in terra




More information about the R-sig-Geo mailing list