recode_to: add layer to current recoding

Description Usage Arguments Value Examples

Description

add layer to current recoding

Usage

1
2
3
4
5
6
7
recode_to(.data, to, where.selected.any = NULL,
  where.selected.all = NULL, where.selected.exactly = NULL,
  where.selected.none = NULL, where.num.equal = NULL,
  where.num.smaller = NULL, where.num.smaller.equal = NULL,
  where.num.larger = NULL, where.num.larger.equal = NULL,
  where = NULL, otherwise.to = NA, skipped.to = NA, na.to = NA,
  questionnaire = NULL, source = NULL)

Arguments

.data

the ongoing recoding obejct, see new_recoding()

to

the value to set the new composition to if the condition is fulfilled

where

an R expression that will be evaluated in the namespace of the data (see example)

otherwise.to

an alternative value to be used if the condition is not fulfilled, the source is not NA and not skipped

skipped.to

an alternative value to be used if the source is NA because the question was skipped (requires to also supply the 'questionnaire' parameter)

na.to

an alternative value to be used if the source is NA but not skipped (and the condition is was not fulfilled)

source

you can set or change the source variable used; this will _continue_ to recode to the same target variable, and will continue to overwrite previously fulfilled conditions.

where.selected..

: a vector of choices; setting values to 'to' where in the source variable any/all/exactly/none of the supplied choices had been selected

where.num...

: a scalar number. setting values to 'to' where the 'source' is equal / smaller / smaller or equal / larger / larger or euqal than the number supplied in where.num...

Value

the updated recoding

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
df<-data.frame(a=1:100,b=sample(letters[1:5],100,T))

df %>%
  new_recoding("new_variable_name",a) %>%
  recode_to("less than 50" ,where.num.smaller = 50) %>%
  recode_to("more or equal 50", where.num.larger.equal = 50) %>%
  recode_to("(size not important = b equals 'd')",where.selected.exactly = "d",source = b) %>%
  end_recoding()


df %>%
  new_recoding("target_var") %>%
  recode_to(5,where = a > 3 & (b %in% letters[1:3])) %>%
  end_recoding

mabafaba/composr documentation built on June 10, 2019, 8:17 a.m.