[R-sig-Geo] stars objects and case_when

Julian M. Burgos ju||@n@burgo@ @end|ng |rom h@|ogv@tn@|@
Mon Sep 14 16:39:39 CEST 2020


Dear list,

I am wondering if there is a way to use logical statements to replace values of a stars object, for example the case_when function or some other "tidyverse friendly" approach.  For example, I can do something like this:

st1 <- read_stars(system.file("tif/L7_ETMs.tif", package = "stars")) %>%
  slice(band, 1)

st1[st1 < 100] <- NA
st1[st1 > 100 & st1 < 150] <- 2

... and so for.  But I am wondering if there is a way to do this as part of a pipe, looking something like this:

st1 <- read_stars(system.file("tif/L7_ETMs.tif", package = "stars")) %>%
  slice(band, 1) %>%
  mutate(x <- case_when (x<100 ~ NA,
                         x>100 & x<150 ~ 2))

Any ideas?

Takk,

Julian

--
Julian Mariano Burgos, PhD
Hafrannsóknastofnun, rannsókna- og ráðgjafarstofnun hafs og vatna/
Marine and Freshwater Research Institute
Botnsjávarsviðs / Demersal Division
  Fornubúðir 5, IS-220 Hafnarfjörður, Iceland
www.hafogvatn.is
Sími/Telephone : +354-5752037
Netfang/Email: julian.burgos using hafogvatn.is



More information about the R-sig-Geo mailing list