R rbind.fill


rbind.fill() function rbinds a list of data frames filling missing columns with NA. This function is located in package "plyr".

> install.packages("plyr", repo="http://cran.r-project.org",dep=TRUE)
> library(plyr)

> x <- trees[c("Girth","Height")]
> x
   Girth Height
1    8.3     70
2    8.6     65
3    8.8     63
...
27  17.5     82
28  17.9     80
29  18.0     80
30  18.0     80
31  20.6     87
> y <- trees[c("Height","Volume")]
> y
   Height Volume
1      70   10.3
2      65   10.3
3      63   10.2
4      72   16.4
...
27     82   55.7
28     80   58.3
29     80   51.5
30     80   51.0
31     87   77.0
> rbind(x,y)
Error in match.names(clabs, names(xi)) :
names do not match previous names


> rbind.fill(x,y)
   Girth Height Volume
1    8.3     70	    NA
2    8.6     65	    NA
3    8.8     63	    NA
4   10.5     72	    NA
5   10.7     81	    NA
6   10.8     83	    NA
7   11.0     66	    NA
8   11.0     75	    NA
9   11.1     80	    NA
10  11.2     75	    NA
11  11.3     79	    NA
12  11.4     76	    NA
13  11.4     76	    NA
14  11.7     69	    NA
15  12.0     75	    NA
16  12.9     74	    NA
17  12.9     85	    NA
18  13.3     86	    NA
19  13.7     71	    NA
20  13.8     64	    NA
21  14.0     78	    NA
22  14.2     80	    NA
23  14.5     74	    NA
24  16.0     72	    NA
25  16.3     77	    NA
26  17.3     81	    NA
27  17.5     82	    NA
28  17.9     80	    NA
29  18.0     80	    NA
30  18.0     80	    NA
31  20.6     87	    NA
32    NA     70   10.3
33    NA     65   10.3
34    NA     63   10.2
35    NA     72   16.4
36    NA     81   18.8
37    NA     83   19.7
38    NA     66   15.6
39    NA     75   18.2
40    NA     80   22.6
41    NA     75   19.9
42    NA     79   24.2
43    NA     76   21.0
44    NA     76   21.4
45    NA     69   21.3
46    NA     75   19.1
47    NA     74   22.2
48    NA     85   33.8
49    NA     86   27.4
50    NA     71   25.7
51    NA     64   24.9
52    NA     78   34.5
53    NA     80   31.7
54    NA     74   36.3
55    NA     72   38.3
56    NA     77   42.6
57    NA     81   55.4
58    NA     82   55.7
59    NA     80   58.3
60    NA     80   51.5
61    NA     80   51.0
62    NA     87   77.0







endmemo.com © 2024  | Terms of Use | Privacy | Home