0

Say I have 3 dataframes as follows:

A<-c(1,2,3,4)
B<-c(5,6,7,8)
data<-data.frame(A,B)
                 
D<-c('a','b','c')
E<-c('d','e','f')
data2<-data.frame(D,E)

F<-c('banana')
G<-c('grape')
data3<-data.frame(F,G)

How can I append data, data2, and data3? I'd expect the result to be a 4 row x 6 column dataframe, containing columns A:G, where the values in each column are the original concatenated lists (e.g. col A is 1, 2, 3, 4). There would be no values for certain columns where the original lists were shorter than the rest (e.g. "F" and "G" would only be 1 row each). (NAs are ok, but better to not have them.)

j400nb
  • 17
  • 5
  • 3
    Maybe this helps https://stackoverflow.com/questions/7962267/cbind-a-dataframe-with-an-empty-dataframe-cbind-fill – Andre Wildberg Dec 24 '21 at 01:09
  • This answer likely will help you if you put your data.frames in a list: https://stackoverflow.com/a/67208065/3460670 – Ben Dec 24 '21 at 01:46
  • 1
    @Andre Wildberg Brilliant, thanks a lot. Yes, this function solves my problem. This specific thing was not easy to search for. – j400nb Dec 24 '21 at 01:47
  • 1
    Thanks @Ben that offers more perspective and options. – j400nb Dec 24 '21 at 01:50

0 Answers0