convert01: Recoding and cleaning of survey data

Description Usage Arguments Examples

Description

Function to convert survey data where 2 is no and 1 is yes.

Usage

1
convert01(df, varName, newVar, trueVal = "1", falseVal = "2")

Arguments

df

to mutate.

varName

variable to convert 1's and 2's to 1's and 0's

newVar

variable name of new variable

trueVal

value(s) to be coded as 1

falseVal

value(s) to be coded as 0

Examples

1
2
3
4
5
6
7
df = data.frame(x = c(2, 1, 9, NA), y = sample(100, 4))

df %>% convert01(varName = 'x', newVar = 'x2')

# Change what's TRUE and FALSE
df %>% convert01(varName = 'x', newVar = 'x2', trueVal = 9, falseVal = '0:2')
df %>% convert01(varName = 'x', newVar = 'x2', trueVal = 'c(2,9)', falseVal = '1')

flaneuse/llamar documentation built on May 16, 2019, 1:18 p.m.