i_recode | R Documentation |
Returns a vector object of class i_labelled
i_recode(
x,
...,
label = NULL,
na_values = NULL,
na_range = NULL,
scale = NULL,
annotation = NULL,
wording = NULL,
subject = NULL,
copy = NULL,
keep_labels = FALSE
)
x |
vector or data.frame |
... |
formula for recoding of values. See examples. |
label |
variable label |
na_values |
a vector with missing values |
na_range |
a vector for missing range |
scale |
scale level (nominal, ordinal, metric) |
annotation |
addition information about variable |
wording |
question text |
subject |
subject |
copy |
When applied to vector: T/F. When applied to a data.frame: a variable from x. Copy the values of an existing variable or x before recoding values according to ... |
keep_labels |
keep value labels from origin vector when copy TRUE or variable from x |
Can be applied to either vector or data.frame. When x is data.frame the formula passed to ... is different from when it is applied to single vector. When function is applied to a data.frame, multiple conditions on multiple variables are possible (e.g when variable X is equal to this, do that; when variable Y is not equal to this, do that, etc.). See examples for further clarification.
You can recode directly via value labels by using
Returns i_labelled vector with values defined by formula and information given to function.
# When applied to a single vector:
# keep in mind that when function is applied to vector, instead of a column use x
myVector <- i_labelled(1:4, labels = c("A" = 1, "B" = 2, "C" = 3, "D" = 4))
i_recode(x = myVector, "AB" = 1 ~ x %in% c("A", "B"), "CD" = 2 ~ x == c(3, 4))
# When applied to data.frame (multiple conditions)
myData <- data.frame(
V1 = i_labelled(1:3, labels = c("A" = 1, "B" = 2, "C" = 3)),
V2 = i_labelled(c(2:3,-9))
)
i_recode(x = myData, A = 1 ~ V1 %in% c("A", "B"), 2 ~ "V2" == 3, "C" = 999 ~ V2 == -9)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.