Description Usage Arguments Functions Examples
grp_routine
functions like a serious of nested ifelse
where
a series of conditions are evaluated and different values are assigned based
on those conditions.
1 2 3 | grp_routine(data, col, ..., ret_factor = FALSE)
grp_routine_(data, col, ..., .dots, ret_factor = FALSE)
|
data |
A |
col |
Name of the generated column. Use a bare name when using NSE functions and a character (quoted) name when using SE functions (functions that end with underscores). |
... |
Specification of group assignment. Use named conditions, like
|
ret_factor |
Whether to convert the column into factor. |
.dots |
Used in conjunction with |
grp_routine_
: SE version of grp_routine.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | df <- data.frame(v1 = letters[1:5], v2 = 1:5)
df
# By default, it creates new groups
grp_routine(df, "group",
first = v1 %in% c("a", "b"),
second = v2 == 3,
third = v2 >= 4)
# Gives a warning when the groups are not collectively exhaustive
grp_routine(df, "group",
first = v1 %in% c("a", "b"),
second = v2 == 3,
third = v2 > 4)
# SE version
grp_routine_(df, "group",
"first" = ~ v1 %in% c("a", "b"),
"second" = ~ v2 == 3,
.dots = setNames(list(~ v2 > 4), "third"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.