set_vall: Set value labels

View source: R/set_vall.R

set_vallR Documentation

Set value labels

Description

A pipe-workflow optimised method to set value labels. This is a wrapper around haven::labelled(), but preserves the original variable label of the vector.

Usage

set_vall(x, value_labels)

Arguments

x

Variable to assign value labels to

value_labels

Named character vector to be assigned as value labels

See Also

Other Labels: set_varl()

Examples


library(magrittr)
library(dplyr)
library(tibble)
tibble(RESPID=1:1000,
       Q1=sample(c(0,1,2),1000,replace=TRUE),
       Q2=sample(c(0,1),1000,replace=TRUE))-> df
df %>%
  mutate_at("Q2",funs(set_varl(.,"What is your answer to this yes/no question?"))) %>%
  mutate_at("Q2",funs(set_vall(.,c("No"=0,"Yes"=1)))) %>%
  .$Q2 %>% attributes()

martinctc/surveytools documentation built on Nov. 21, 2024, 10:48 p.m.