<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { margin-top: 0 ; margin-bottom: 0 }
--></style><title>Re: [R] rbind and data.frame</title></head><body>
<div>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) :</div>
<div><tt><font color="#000000">></font><font color="#0000FF">
rbind(as.matrix(dat),x)<br>
</font><font color="#000000"> V1 V2<br>
1 1 2<br>
2 0 0<br>
3 0 0<br>
></font><font color="#0000FF"> xdat_as.data.frame(x)<br>
</font><font color="#000000">></font><font color="#0000FF">
names(x)_names(dat)<br>
</font><font color="#000000">></font><font color="#0000FF">
rbind(dat,x)<br>
</font><font color="#000000"> x y<br>
1 1 2<br>
2 0 0</font></tt></div>
<div><tt><font color="#000000">3 0 0</font></tt></div>
<div><br></div>
<div>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 !!</div>
<div><br></div>
<div><tt><font color="#000000">></font><font color="#0000FF">
y_matrix(c(3,4,5,6),2,2)<br>
</font><font color="#000000">></font><font color="#0000FF"> y<br>
</font><font color="#000000"> [,1] [,2]<br>
[1,] 3 5<br>
[2,] 4 6<br>
></font><font color="#0000FF"> rbind(dat,y)<br>
</font><font color="#000000"> x y<br>
1 1 2<br>
2 3 4<br>
></font></tt></div>
<div><br></div>
<blockquote type="cite" cite>Version 1.3.1 (2001-08-31) (RH
7.2):<br>
</blockquote>
<blockquote type="cite" cite>> dat <- data.frame(x = 1, y =
2)<br>
> x <- matrix(0, ncol = 2, nrow = 2)</blockquote>
<blockquote type="cite" cite>> x<br>
[,1] [,2]<br>
[1,] 0 0<br>
[2,] 0 0<br>
> dat<br>
x y<br>
1 1 2<br>
> rbind(dat, x)<br>
x y<br>
1 1 2<br>
2 0 0<br>
<br>
I expected<br>
<br>
> rbind(dat, x)<br>
x y<br>
1 1 2<br>
2 0 0<br>
3 0 0<br>
<br>
Is my expectation wrong?<br>
<br>
Göran Broström<br>
<br>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-<span
></span>.-.-.-.-.-<br>
r-help mailing list -- Read
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html<br>
Send "info", "help", or
"[un]subscribe"<br>
(in the "body", not the subject !) To:
r-help-request@stat.math.ethz.ch<br>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._<span
></span>._._._._._</blockquote>
<div><br></div>
<div>-- <br>
Stéphane DRAY<br>
---------------------------------------------------------------<br>
Biométrie et Biologie évolutive - Equipe "Écologie
Statistique"<br>
Universite Lyon 1 - Bat 711 - 69622 Villeurbanne CEDEX - France<br>
<br>
Tel : 04 72 43 27 56<x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab> Fax : 04 78 89 27 19<br>
04 72 43 27 57 <x-tab>
</x-tab> E-mail : dray@biomserv.univ-lyon1.fr
---------------------------------------------------------------<br>
ADE-4 <span
></span>
http://pbil.univ-lyon1.fr/ADE-4/ADE-4F.html<br>
---------------------------------------------------------------</div>
</body>
</html>