FacsToChars: Convert all 'factor' columns to 'character' columns in a...

Description Usage Arguments Author(s) See Also Examples

Description

Sometimes, we forget to use the stringsAsFactors argument when using 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

1
  FacsToChars(mydf, overwrite = FALSE)

Arguments

mydf

The name of your data.frame

overwrite

Logical. Should the current object be overwritten? Defaults to FALSE

Author(s)

Ananda Mahto

See Also

read.table

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Some example data
dat <- data.frame(title = c("title1", "title2", "title3"),
              author = c("author1", "author2", "author3"),
              customerID = c(1, 2, 1))
## Make a copy of dat for later
dat_copy <- dat
str(dat) # current structure
dat2 <- FacsToChars(dat)
str(dat2) # Your new object
str(dat)  # Original object is unaffected

## You can also overwrite the existing object
str(dat_copy) # Before applying the function
FacsToChars(dat_copy, overwrite=TRUE)
str(dat_copy) # After applying the function

mrdwab/AMsnippets documentation built on May 23, 2019, 7:15 a.m.