geocompx / geocompr

Geocomputation with R: an open source book
https://r.geocompx.org/
Other
1.59k stars 584 forks source link

Subsetting multilayer rasters with double brackets [[ ]] #1024

Closed tibbles-and-tribbles closed 11 months ago

tibbles-and-tribbles commented 11 months ago

In subsection 4.3.3 (https://r.geocompx.org/spatial-operations#local-operations) a multilayer raster is subsetted with double brackets in a call to lapp()

ndvi_rast = lapp(multi_rast[[c(4, 3)]], fun = ndvi_fun)

This type of subsetting hasn't been covered yet (as far as can I remember). Appears to be equivalent to the function subset(), which was covered earlier. Could replace with subset(multi_rast, c(4, 3)).

Nowosad commented 11 months ago

Thanks!

I've checked -- [[ are mentioned in footnote 20 in https://r.geocompx.org/spatial-class.

As I use [[ more often than subset(), I will move that part from a footnote to the regular text.