set.col.type {eatPrep} | R Documentation |
This function converts the classes of columns to character
, numeric
, logical
, integer
or factor
.
set.col.type(dat, col.type = list("character" = NULL), verbose = FALSE, ...)
dat |
A data frame |
col.type |
A named list of column names that are to be converted. The names of the list indicate the class to which the respective column should be converted ( |
verbose |
if |
... |
Additional arguments to be passed to |
Use col.type="numeric.if.possible"
if conversion to numeric should be tested upfront, see asNumericIfPossible
for details.
A data frame with column classes changed according to the specifications in col.type
Martin Hecht, Karoline Sachse
str(d <- data.frame("var1" = 1, "var2" = TRUE, "var3" = FALSE, "var4" = as.factor(1), "var5" = as.factor("a"),"var6" = "b", stringsAsFactors = FALSE)) str(set.col.type(d)) str(set.col.type(d, list("numeric" = NULL))) str(set.col.type(d, list("character" = c("var1" , "var2"), "numeric" = "var3", "logical" = "var4"))) str(set.col.type(d, list("numeric.if.possible" = NULL))) str(set.col.type(d, list("numeric.if.possible" = NULL), transform.factors = TRUE)) str(set.col.type(d, list("numeric.if.possible" = NULL), transform.factors = TRUE, maintain.factor.scores = FALSE))