-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecbq_numeric.R
More file actions
32 lines (29 loc) · 1.04 KB
/
ecbq_numeric.R
File metadata and controls
32 lines (29 loc) · 1.04 KB
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
ecbq_numeric <- function(var_lbl = "unfamiliarperson",
df,
levels = c(1:7),
labels = c(
"never",
"veryrarely",
"lessthanhalf",
"abouthalf",
"morethanhalf",
"almostalways",
"always"
)) {
assertthat::is.string(var_lbl)
assertthat::assert_that(is.data.frame(df))
df <- df |>
dplyr::select({{ var_lbl }}) |>
dplyr::filter(!is.na(.data[[var_lbl]])) |>
dplyr::mutate("num_{{var_lbl}}" :=
dplyr::case_match({{var_lbl}},
"never" ~ 1,
"veryrarely" ~ 2,
"lessthanhalf" ~ 3,
"abouthalf" ~ 4,
"morethanhalf" ~ 5,
"almostalways" ~ 6,
"always" ~ 7,
"na" ~ NA))
df
}