On May 7, 2013, at 10:54 AM, Chris Stubben wrote: > >> First off, stop using cbind() when it is not needed. You will not see the >> reason when the columns are all numeric but you will start experiencing pain >> and puzzlement when the arguments are of mixed classes. The data.frame >> function will do what you want. (Where do people pick up this practice >> anyway?) > > Maybe from help( data.frame)? > > It's in most of the examples and is not needed ... > > L3 <- LETTERS[1:3] > (d <- data.frame(cbind(x=1, y=1:10), fac=sample(L3, 10, replace=TRUE))) > ## The same with automatic column names: > data.frame(cbind( 1, 1:10), sample(L3, 10, replace=TRUE)) > > Chris
There are many instances of new users posting questions to R-help where they use the form: dfrm <- data.frame(cbind(1:10, letter[1:10]) ) … and predictably get a character mode for all their columns. I was pointed to the help page for `data.frame` as one possible source of this confusion. I would like to request that the examples be changed to: L3 <- LETTERS[1:3] (d <- data.frame(x = 1, y = 1:10, fac = sample(L3, 10, replace = TRUE))) ## The same with automatic column names: data.frame( 1, 1:10, sample(L3, 10, replace = TRUE)) -- David Winsemius Alameda, CA, USA ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel