grp_routine: Mutate a character/factor based on conditions.

Description Usage Arguments Functions Examples

View source: R/grp_routine.R

Description

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.

Usage

1
2
3
grp_routine(data, col, ..., ret_factor = FALSE)

grp_routine_(data, col, ..., .dots, ret_factor = FALSE)

Arguments

data

A data.frame or tbl.

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 top2 = x > 5.

ret_factor

Whether to convert the column into factor.

.dots

Used in conjunction with ... to support both explicit and implicit arguments.

Functions

Examples

 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"))

extdplyr documentation built on April 20, 2020, 9:04 a.m.