[R] data.frame

Chong Gu chong at stat.purdue.edu
Mon Jun 7 23:55:15 CEST 1999


I am not sure if I should call this a bug or just a design
imperfection.

I have noticed that the data.frame function does not preserve the
integrity of multivariate components.  Here is a simple illustration:

> x <- matrix(1:6,3,2)
> y <- 1:3
> z <- data.frame(x=x,y=y)
> z$x 
# NULL
> z$y 
# [1] 1 2 3

One can however get by that by using model.frame:

> zz <- model.frame(~x+y)
> zz$x
#      [,1] [,2]
# [1,]    1    4
# [2,]    2    5
# [3,]    3    6

I was expecting data.frame to behave like this.

I am developing some multivariate nonparametric modeling tools using
smoothing splines, with syntax similar to lm and glm.  In a formula
say y~x1*x2, x1 or x2 or both can be multivariate.  The corresponding
predict function also has syntax similar to that of lm.  To prepare
newdata to be used in predict(object,newdata,...), I can use

> newdata <- data.frame(x1=newx1,x2=newx2)

only for univariate x1 and x2.  For multivariate predictors, I have to
fake it by using

> newdata <- model.frame(~x1+x2,list(x1=newx1,x2=newx2))

Chong Gu
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list