A pipe-workflow optimised method to set variable labels.
set_varl(x, variable_label)
Other Labels:
set_vall()
library(tibble)
library(dplyr)
library(magrittr)
df <-
tibble(RESPID=1:1000,
Q1=sample(c(0,1,2),1000,replace=TRUE),
Q2=sample(c(0,1),1000,replace=TRUE))
df %>%
mutate_at("Q1",funs(set_varl(.,"Which of the following groups do you fall into?"))) %>%
.$Q1
#> Warning: `funs()` was deprecated in dplyr 0.8.0.
#> ℹ Please use a list of either functions or lambdas:
#>
#> # Simple named list: list(mean = mean, median = median)
#>
#> # Auto named with `tibble::lst()`: tibble::lst(mean, median)
#>
#> # Using lambdas list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
#> [1] 1 2 2 0 2 0 1 1 0 1 2 2 0 1 2 2 0 0 2 1 2 2 1 0 2 0 0 1 1 1 0 2 2 1 0 1 1
#> [38] 2 2 0 2 1 2 2 1 1 2 0 1 0 1 0 2 2 1 2 0 1 1 2 0 2 0 2 2 0 2 0 2 0 2 0 0 0
#> [75] 1 2 2 2 0 2 1 2 0 1 2 1 0 1 2 0 2 1 0 1 0 1 1 1 2 0 0 2 2 1 0 2 1 0 1 0 2
#> [112] 0 0 2 1 1 2 1 0 2 0 0 0 0 1 0 1 2 1 2 2 1 0 1 2 0 0 0 2 2 0 0 0 2 1 1 2 0
#> [149] 0 1 2 1 1 0 0 0 1 0 2 1 1 2 1 0 0 0 2 1 0 0 2 0 1 0 1 0 0 2 2 0 1 2 1 0 0
#> [186] 1 2 1 2 2 2 0 2 0 1 2 1 0 0 1 1 2 1 1 1 1 2 1 2 0 0 1 0 2 1 2 0 0 0 1 1 2
#> [223] 2 0 1 2 2 0 2 1 0 2 0 2 1 2 2 1 2 0 0 0 1 2 2 0 2 0 0 1 1 0 1 1 0 1 1 0 0
#> [260] 1 1 2 2 2 2 2 0 1 0 2 2 1 0 1 0 1 1 0 0 1 0 1 0 2 2 2 0 1 2 1 1 1 1 0 2 1
#> [297] 2 1 1 0 0 2 1 1 2 0 1 1 1 0 0 1 2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