Description Usage Arguments Value Examples
View source: R/cutoffs_modify_at.R
To be specific, given a cutoff-value for each variables of data.frame, if the value of variable is greater than the corresponding cutoff, the value of variable will be changed to 0, otherwise changed to 1.
Thanks (Misha Balyasin)[https://github.com/romatik] for great help.
1 | cutoffs_modify_at(df, .vars, cutoffs)
|
df |
data.frame |
.vars |
specify the variables which to be cutoffs, for example, .vars = c(x, y, z) or .vars = x |
cutoffs |
a list or vector containts cutoffs-value for variables, this vector has the same length as .vars |
deprivation data.frame
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | df <- tribble(
~id, ~x, ~y, ~z, ~g,
#--|--|--|--|--
"a", 13.1, 14, 4, 1,
"b", 15.2, 7, 5, 0,
"c", 12.5, 10, 1, 0,
"d", 20, 11, 3, 1
)
cutoffs <- c(
x = 13,
y = 12,
z = 3
)
df %>%
cutoffs_modify_at(c(x), cutoffs = c(x = 13))
df %>%
cutoffs_modify_at(x, cutoffs = c(x = 13))
df %>%
cutoffs_modify_at(.vars = c(x, y), cutoffs = cutoffs)
df %>%
cutoffs_modify_at(.vars = c(x, y, z), cutoffs = cutoffs)
df %>%
cutoffs_modify_at(.vars = c(x, y, starts_with("z")), cutoffs = cutoffs)
df %>%
cutoffs_modify_at(.vars = x:z, cutoffs = cutoffs)
df %>%
cutoffs_modify_at(.vars = -id, cutoffs = cutoffs)
df %>%
cutoffs_modify_at(.vars = c(x, y, ends_with("z")), cutoffs = cutoffs)
df %>%
cutoffs_modify_at(.vars = c(x, y, starts_with("z")), cutoffs = cutoffs)
df %>%
cutoffs_modify_at(.vars = c(x, y, contains("z")), cutoffs = cutoffs)
df %>%
cutoffs_modify_at(.vars = c(x, y, matches("z")), cutoffs = cutoffs)
df %>%
cutoffs_modify_at(.vars = one_of("x", "y", "z"), cutoffs = cutoffs)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.