Description Usage Arguments See Also Examples
View source: R/conditional_dplyr.R
Perform mutate if condition is met. This function is a simple wrapper for
mutate
.
1 | conditional_mutate(df1, cond, LHS, RHS)
|
df1 |
A dataframe |
cond |
A logical value indicating if mutate should be performed |
varName |
Name of variable to create |
Other conditional dplyr: conditional_filter
,
conditional_range_filter
,
conditional_select
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | mtcars %>%
dplyr::as_tibble() %>%
conditional_mutate(
exists("cyl", where = .),
LHS = cyl2,
RHS = cyl * 2
)
mtcars %>%
dplyr::as_tibble() %>%
conditional_mutate(
exists("cyl2", where = .),
LHS = cyl4,
RHS = cyl2 * 2
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.