set.col.type: Set the Class of Columns in a Data Frame

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Convert the Class of Columns to character, numeric, logical, integer or factor

Usage

1
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

See Also

asNumericIfPossible

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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))

eatTools documentation built on May 2, 2019, 4:44 p.m.