Thursday, 28 September 2017

R data.frame

Cited from the Book "Beginning Data Science in R"

By default, a data frame will consider a character vector as a factor, and you need to tell it explicitly not to if you want a character vector.

df <- data.frame(a = 1:4, b = letters[1:4], stringsAsFactors = FALSE)

Functions for reading in data from various text formats will typically also convert string vectors to
factors, and you need to prevent this explicitly.
The readr package (see
https://github.com/hadley/readr) is a notable exception where the default is to treat character vectors as character vectors.
 

No comments:

Post a Comment