[R] rbind()

From: Yevgeniy Kirpichevsky <kirpich_at_fas.harvard.edu>
Date: Sat 24 Jul 2004 - 14:58:56 EST


hi. I'm merging two datasets.
one of them is 51 rows, and a typical row looks like this:

midwar[midwar$dispnum==89,]

    dispnum synch sanum saname sbnum sbname year1 yearn ainit binit fatala

158      89     0   220    FRN   230    SPN  1822  1823     1     1      4
     fatalb       key1       keyn warnum year1.war yearn.war awon
158      5 2202301822 2202301823      1      1823      1823    2

The other is 3 rows, and it looks like this:

   dispnum synch sanum saname sbnum sbname year1 yearn ainit binit fatala fatalb
7 NA NA 70 MEX 220 FRN NA NA NA NA NA NA    key1 keyn warnum year1.war yearn.war awon 7 NA NA 40 1862 1867 2

So the column names are identical, and rbind() shouldn't create problems. Here's what happens now when I call this: midwar[midwar$dispnum==89,]

      dispnum synch sanum saname sbnum sbname year1 yearn ainit binit fatala
158       89     0   220    FRN   230    SPN  1822  1823     1     1      4
NA        NA    NA    NA   <NA>    NA   <NA>    NA    NA    NA    NA     NA
NA.1      NA    NA    NA   <NA>    NA   <NA>    NA    NA    NA    NA     NA
NA.2      NA    NA    NA   <NA>    NA   <NA>    NA    NA    NA    NA     NA
      fatalb       key1       keyn warnum year1.war yearn.war awon
158       5 2202301822 2202301823      1      1823      1823    2
NA       NA         NA         NA     NA        NA        NA   NA
NA.1     NA         NA         NA     NA        NA        NA   NA
NA.2     NA         NA         NA     NA        NA        NA   NA

It gives me extra 3 rows of NAs for each row of the original data set. The only thing that I can think of that may be going on is that in the first data set the names of counties are vectors of factors, and in the second data set they are characters. Could that be causing a problem? I can't check, because I can't make factor vectors into character vectors (as.character() didn't work).

Sorry for the rambling question. Any insights are appreciated,

-yev



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Jul 24 15:07:39 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:55:12 EST