rbind (PR#2266)

louisept@pweh.com louisept@pweh.com
Thu, 7 Nov 2002 01:47:52 +0100 (MET)


Full_Name: Paul Louisell
Version: 1.6.0
OS: Windows NT
Submission from: (NULL) (192.249.47.9)


'rbind' does not work properly when one object is a data frame and the other is
a matrix. See the code below; this is copied directly from an R session. It
appears the objects need to be in the same class for rbind to work correctly.

> test=matrix(1:25, 5, 5)
> test=as.data.frame(test)
> test
  V1 V2 V3 V4 V5
1  1  6 11 16 21
2  2  7 12 17 22
3  3  8 13 18 23
4  4  9 14 19 24
5  5 10 15 20 25
> test1=matrix(-(1:10), 2, 5)
> test1
     [,1] [,2] [,3] [,4] [,5]
[1,]   -1   -3   -5   -7   -9
[2,]   -2   -4   -6   -8  -10
> rbind(test, test1)
  V1 V2 V3 V4 V5
1  1  6 11 16 21
2  2  7 12 17 22
3  3  8 13 18 23
4  4  9 14 19 24
5  5 10 15 20 25
6 -1 -2 -3 -4 -5
> rbind(as.matrix(test), test1)
  V1 V2 V3 V4  V5
1  1  6 11 16  21
2  2  7 12 17  22
3  3  8 13 18  23
4  4  9 14 19  24
5  5 10 15 20  25
  -1 -3 -5 -7  -9
  -2 -4 -6 -8 -10
> rbind(test, as.data.frame(test1))
   V1 V2 V3 V4  V5
1   1  6 11 16  21
2   2  7 12 17  22
3   3  8 13 18  23
4   4  9 14 19  24
5   5 10 15 20  25
11 -1 -3 -5 -7  -9
22 -2 -4 -6 -8 -10


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._