set.col.type {eatTools}R Documentation

Set the Class of Columns in a Data Frame

Description

This function converts the classes of columns to character, numeric, logical, integer or factor.

Usage

set.col.type(dat, col.type = list("character" = NULL), verbose = FALSE, ...)

Arguments

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 (character, numeric, numeric.if.possible, logical, integer or factor)

verbose

if TRUE details about converted columns are printed on the console

...

Additional arguments to be passed to asNumericIfPossible

Details

Use col.type="numeric.if.possible" if conversion to numeric should be tested upfront, see asNumericIfPossible for details.

Value

A data frame with column classes changed according to the specifications in col.type

Author(s)

Martin Hecht, Karoline Sachse

See Also

asNumericIfPossible

Examples

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))

[Package eatTools version 0.7.6 Index]