cutoffs_modify_at: To obtain deprivation data.frame

Description Usage Arguments Value Examples

View source: R/cutoffs_modify_at.R

Description

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.

Usage

1
cutoffs_modify_at(df, .vars, cutoffs)

Arguments

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

Value

deprivation data.frame

Examples

 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)

perlatex/easyuse documentation built on April 14, 2020, 5:35 a.m.