Difference between SPlus & R question
On Thu, 22 Jun 2000, Marc Feldesman wrote:
In S-Plus, I do the following: v1<-rnorm(50) v2<-rnorm(50) v3<-"gorilla" v4<-cbind(v1, v2) v5<-data.frame(v4, v5)
v5<-data.frame(v4, v3)?
v5 is a dataframe with 50 rows and 3 columns. The third column has "gorilla" replicated for all 50 rows - the behavior I desire. (It also works if I simply do: v5<-data.frame(v1, v2, v3) leaving out the cbind() step altogether.
These do not work in S-PLUS 3.4 (`the prototype').
If I try the same thing in R, it rejects v5, reporting an error that v4 has 50 rows while v3 has 1 row. What is the proper way to achieve the same result in R?
data.frame(v1, v2, v3=rep("gorilla", 50))
will certainly do.
The bug (if it is considered to be one) is at the line
if (length(xi) == 1 && nr%%nrows[[i]] == 0 && is.vector(xi[[1]]))
value[[i]] <- list(rep(xi[[1]], length = nr))
in data.frame. is.vector is too severe a test, failed by a factor.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._