Description Usage Arguments Details Value Examples
View source: R/index_cfactor.R
Decode numerical columns in a data frame into (ordered) factors given the encoding in another data frame.
1 2 | index_cfactor(data, index, variable = "variable", encoding = "encoding",
label = "label", ...)
|
data |
A data frame containing at least one integer column to decode. |
index |
A data frame containing the names of the variable to encode,
the encoding for |
variable |
The name of the column in |
encoding |
The name of the column in |
label |
The name of the column in |
... |
Further arguments to be passed to or from other methods,
in particular to |
Arguments passed via ...
to cfactor
are only recycled
if of length 1. Otherwise, an error is thrown.
All arguments passed via ...
are applied in the order of the data
columns but columns not to convert are skipped (see example).
The original data frame is returned whereas the variables for which an encoding was provided are turned into (ordered) factors. All other columns are returned unmodified.
1 2 3 4 5 6 7 8 9 10 11 12 | data <- data.frame(var1 = sample(x = 1:10, size = 20, replace = TRUE),
var2 = rep(1:2, 20),
var3 = sample(20),
var4 = 2,
var5 = sample(row.names(USArrests), size = 20),
stringsAsFactors = FALSE)
index <- data.frame(var = rep(paste0("var", 1:3), c(10, 2, 20)),
encoding = c(1:10, 1:2, 1:20),
label = c(letters[1:10], c("male", "female"), LETTERS[1:20]))
index_cfactor(data = data, index = index, variable = "var", ordered = c(TRUE, TRUE, FALSE))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.