library(terra)
f <- system.file("extdata/cyl_tile.tif", package = "tidyterra")
r <- rast(f)
# Extract second layer
r |>
pull(2) |>
head()
# With xy the first two cols are `x` (longitude) and `y` (latitude)
r |>
pull(2, xy = TRUE) |>
head()
# With renaming
r |>
mutate(cat = cut(cyl_tile_3, c(0, 100, 300))) |>
pull(cyl_tile_3, name = cat) |>
head()
Run the code above in your browser using DataLab