Tag Info

2

Given that the data is in a native R array in dataR\$X, the most direct approach would be to work with that rather than add several layers of add-on packages and unneccessary data structure manipulation. Using tapply, here's median on the first two layers: > tapply(dataR\$X[,,"inflatable_partridge"],dataR\$X[,,3], median) 1 2 3 4 47.0 ...

2

If you work on the slices rather than the matrix versions then your new layer is going to be: L3 = slice(toy_data,"attributes",1) < 40 & slice(toy_data,"attributes", 2) > 60 Then you can update your toy_data this way. toy_data = merge(c(split(toy_data),L3)) Then plot(slice(toy_data, "attributes", 3)) shows 0s ...

1

If you create polygons form a raster with values, the NA's are removed by terra::as.polygons unless you set na.rm=FALSE. If the NAs are at the edges (as they often are), the extent can get reduced. Otherwise, I do not see a change in the extent: library(terra) r <- rast(xmin=488532.1, xmax=488650.3, ymin=4424048, ymax=4424103, nrow=2744, ncol=5907) x <-...

2

If you want to try a different approach I would recommend using terra (Rcpp based replacement for raster package). To read a raster it would be r <- terra::rast("x") and, to convert to polygon you use terra:as.polygons. Since this results in a Vect object class (which are a pain to work with outside of terra) you can nest the polygon conversion ...

0

The key is the dims argument data\$band = c("red", "blue", "green", "alpha")[data\$band] r <- st_as_stars(data, dims = c("x", "y", "band")) See also https://stackoverflow.com/questions/67641493/how-can-i-cast-a-data-frame-to-a-stars-object-with-a-time-dimension

Top 50 recent answers are included