Learn R Programming

splitstackshape (version 1.4.8)

FacsToChars: Convert All Factor Columns to Character Columns

Description

Sometimes, we forget to use the stringsAsFactors argument when using utils::read.table() and related functions. By default, R converts character columns to factors. Instead of re-reading the data, the FacsToChars function will identify which columns are currently factors, and convert them all to characters.

Usage

FacsToChars(mydf)

Arguments

mydf

The name of your data.frame

See Also

utils::read.table()

Examples

Run this code
# NOT RUN {
## Some example data
dat <- data.frame(title = c("title1", "title2", "title3"),
         author = c("author1", "author2", "author3"),
         customerID = c(1, 2, 1))

str(dat) # current structure
dat2 <- splitstackshape:::FacsToChars(dat)
str(dat2) # Your new object
str(dat)  # Original object is unaffected

# }

Run the code above in your browser using DataLab