It seems to be contrary to what is written in the help file:
"If a list or data frame or matrix is passed to data.frame it is as if each component or column had been passed as a separate argument"
So what do I do wrong ?
Example code:
d <- c("bla", "bla", "blou", "blou", "bli")
dtest <- data.frame(d, stringsAsFactors=FALSE)
dtest2 <- data.frame(dtest, stringsAsFactors=TRUE)
dtest3 <- data.frame(dtest[[1]], stringsAsFactors=TRUE)
str(c(dtest2, dtest3))
One is a character vector, the other has been converted to a factor (following the stringsAsFactor=TRUE behavior). They "should" be both factors.
I actually want to use data.frame(df) to convert an existing data frame with some character columns into a data frames with the corresponding factors.
i <- sapply(df,is.character) df[i] <- lapply(df[i], as.factor)
But the question of parsing the data frames is still raised! – Antoine Lizée