Factor Madness
Yep, but I figured that out quite fast ;0) Thanks for giving me a hand ... you want believe a many times I skimmed the cbind help without actually seeing this ... well, it was 0:30 ... Thanks again, Joh
Tony Plate wrote:
Whoops, it looks like there's a typo in ?cbind (R version 2.6.0 Patched (2007-10-11 r43143)), and I blindly copied it into my message. That should read (emphasis added): "and convert character columns to factors unless stringsAsFactors = ***FALSE***" Here's an example:
> x <- data.frame(X=1:3) > sapply(cbind(x, letters[1:3]), class)
X letters[1:3]
"integer" "factor"
> sapply(cbind(x, letters[1:3], stringsAsFactors=FALSE), class)
X letters[1:3]
"integer" "character"
>
Thanks to Mark Leeds for pointing that out to me in a private message! (I see this still in the source at https://svn.r-project.org/R/trunk/src/library/base/man/cbind.Rd -- is that the right place to look for the latest source to make sure it hasn't been fixed already?) -- Tony Plate Tony Plate wrote:
From ?cbind: Data frame methods The cbind data frame method is just a wrapper for data.frame(..., check.names = FALSE). This means that it will split matrix columns in data frame arguments, and convert character columns to factors unless stringsAsFactors = TRUE is passed. (I'm guessing 'spectrum' is a data.frame before the code fragment you've shown) hope this helps, Tony Plate Johannes Graumann wrote:
Why is class(spectrum[["Ion"]]) after this "factor"?
spectrum <- cbind(spectrum,Ion=rep("",
nrow(spectrum)),Deviation.AMU=rep(0.0, nrow(spectrum)))
slowly going crazy ...
Joh
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.