View source: R/dplyr_extensions.R
update_by | R Documentation |
update columns conditionally
update_by(D, by, ...)
D |
data frame |
... |
expressions |
filter |
predicate function (like dplyr::filter) |
data frame
Applies mutations to the filtered group, only.
Martin Schmettow
D <- tribble(~group, ~value, 1, 4, 1, 9, 2, -4, 2, -9)
D %>% mutate(value = if_else(group == 1, sqrt(value), value))
## Produces NaNs, because sqrt() is evaluated before selection
D %>% mutate_by(group == 1, value = sqrt(value))
## sqrt() is only evaluated
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.