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. >
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
What was spectrum orginally? --- Johannes Graumann <johannes_graumann at web.de> 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. >
As Tony assumed: a data frame. Joh John Kane wrote:> What was spectrum orginally? > > > --- Johannes Graumann <johannes_graumann at web.de> > 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.
You may be haning Ion coerced into a factor. Have a look at http://finzi.psych.upenn.edu/R/Rhelp02a/archive/98260.html for some discussion of this. I find that I usually set options(stringsAsFactors = FALSE) just because of this but as Gabor points out it may have its own disadvantages in sharing code. I spent 2 hours once trying to get an example to work only to find that the code assume options(stringsAsFactors = TRUE). --- Johannes Graumann <johannes_graumann at web.de> wrote:> As Tony assumed: a data frame. > > Joh > > John Kane wrote: > > > What was spectrum orginally? > > > > > > --- Johannes Graumann <johannes_graumann at web.de> > > 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. >