<!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&nbsp; 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">&gt;</font><font color="#0000FF">
rbind(as.matrix(dat),x)<br>
</font><font color="#000000">&nbsp; V1 V2<br>
1&nbsp; 1&nbsp; 2<br>
2&nbsp; 0&nbsp; 0<br>
3&nbsp; 0&nbsp; 0<br>
&gt;</font><font color="#0000FF"> xdat_as.data.frame(x)<br>
</font><font color="#000000">&gt;</font><font color="#0000FF">
names(x)_names(dat)<br>
</font><font color="#000000">&gt;</font><font color="#0000FF">
rbind(dat,x)<br>
</font><font color="#000000">&nbsp; 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">&gt;</font><font color="#0000FF">
y_matrix(c(3,4,5,6),2,2)<br>
</font><font color="#000000">&gt;</font><font color="#0000FF"> y<br>
</font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp; [,1] [,2]<br>
[1,]&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp; 5<br>
[2,]&nbsp;&nbsp;&nbsp; 4&nbsp;&nbsp;&nbsp; 6<br>
&gt;</font><font color="#0000FF"> rbind(dat,y)<br>
</font><font color="#000000">&nbsp; x y<br>
1 1 2<br>
2 3 4<br>
&gt;</font></tt></div>
<div><br></div>
<blockquote type="cite" cite>Version 1.3.1&nbsp; (2001-08-31) (RH
7.2):<br>
</blockquote>
<blockquote type="cite" cite>&gt; dat &lt;- data.frame(x = 1, y =
2)<br>
&gt; x &lt;- matrix(0, ncol = 2, nrow = 2)</blockquote>
<blockquote type="cite" cite>&gt; x<br>
&nbsp;&nbsp;&nbsp;&nbsp; [,1] [,2]<br>
[1,]&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp; 0<br>
[2,]&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp; 0<br>
&gt; dat<br>
&nbsp; x y<br>
1 1 2<br>
&gt; rbind(dat, x)<br>
&nbsp; x y<br>
1 1 2<br>
2 0 0<br>
<br>
I expected<br>
<br>
&gt; rbind(dat, x)<br>
&nbsp; 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 &quot;info&quot;, &quot;help&quot;, or
&quot;[un]subscribe&quot;<br>
(in the &quot;body&quot;, not the subject !)&nbsp; 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 &quot;Écologie
Statistique&quot;<br>
Universite Lyon 1 - Bat 711 - 69622 Villeurbanne CEDEX - France<br>
<br>
Tel : 04 72 43 27 56<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</x-tab><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</x-tab><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</x-tab>&nbsp;&nbsp; Fax : 04 78 89 27 19<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 04 72 43 27 57 <x-tab>&nbsp;&nbsp;&nbsp;
</x-tab>&nbsp;&nbsp; E-mail : dray@biomserv.univ-lyon1.fr
---------------------------------------------------------------<br>
ADE-4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span
></span>&nbsp;&nbsp;&nbsp;&nbsp;
http://pbil.univ-lyon1.fr/ADE-4/ADE-4F.html<br>
---------------------------------------------------------------</div>
</body>
</html>