[R] rbind and data.frame

Göran Broström gb at stat.umu.se
Wed Dec 5 12:32:26 CET 2001


On Wed, 5 Dec 2001, Stephane Dray wrote:

> I think that the problem  is that you want to bind a matrix and a
> data frame. You must transform your dataframe in a matrix (or the
> matrix in dataframe) :
> >  rbind(as.matrix(dat),x)
>    V1 V2
> 1  1  2
> 2  0  0
> 3  0  0
> >  xdat_as.data.frame(x)
> >  names(x)_names(dat)
> >  rbind(dat,x)
>    x y
> 1 1 2
> 2 0 0
> 3 0 0
> 
> If you bind the matrix and the dataframe, only the first column of
> the matrix is added as a row ... and i don't know (and understand)
> why !!

That's because, as Peter explained, the matrix is viewed as a vector
by rbind, and the rule is 'columnwise' (ala Fortran).

[...]

Göran

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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