mutate_cond | R Documentation |
Execute dplyr mutate only for rows satisfying condition
mutate_cond(.data, condition, ..., envir = parent.frame())
.data |
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr) |
condition |
condition for |
... |
<data-masking> Name-value pairs. The name gives the name of the column in the output. |
envir |
environment default( parent.frame()) |
ken4rab
library(dplyr) df <- data.frame(a = c("X", "Y"), b = 0) df <- df %>% mutate_cond(a == "X", b = 1) df
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.