Learn R Programming

epifit (version 0.1.2)

convertFromFactor: Convert factor variable to numeric or character variable.

Description

Convert factor variable to numeric or character variable.

Usage

convertFromFactor(data = NULL, numeric = c(""), character = c(""), mode = c("automatic", "only_specified", "all_character", "all_numeric"))

Arguments

data
a data.frame which contains factor variables.
numeric
a character vector specifying variable names to be converted into numeric variables.
character
a character vector specifying variable names to be converted into character variables.
mode
a character vector specifying converting mode. See details and the default is ‘only_specified’.

Value

a converted data.frame.

Details

This function convert factor variable to numeric or character variable. In ‘automatic’ mode, all variables not specified by numeric or character arguments are converted into numeric or character automatically. Explicitly specified variables are converted as specified. In ‘only_specified’ mode, variables specified by numeric argument is converted into numeric variables, and the character is conveted into character variables. When converted into numeric variable, NAs can be produced for incompatible data with warnings. In ‘all_character’, and ‘all_numeric’ modes, all factor variables are converted into character or numeric variables, respectively.

See Also

showContents, listNumericIncompatibility

Examples

Run this code
a <- factor(rnorm(5))
b <- c("a", "b", "c", "d", "e")
c <- c("1", "2", "3", "4", NA)
d <- c("1", "2", "3", "4", ".")
dat <- data.frame(a,b,c,d)
dat2 <- convertFromFactor(dat)
dat3 <- convertFromFactor(dat, numeric=c("d"))
dat4 <- convertFromFactor(dat, mode="all_character")

Run the code above in your browser using DataLab