Concatenate data frames in R

29 views Asked by At

I have four data frames with different headers and different no of rows. I want to append all four data frames in one data frame leaving few rows empty between data frames in R. For example:

DF1:

Column A Column B
Cell 1 Cell 2
Cell 3 Cell 4

DF2:

enter image description here

DF3:

enter image description here

DF4:

enter image description here

Result DataFrame:

enter image description here

I tried rbind and bind_rows functions, but it did not give what I am looking for.

I want the following result after appending/concatenating the four data frames.

1

There are 1 answers

2
stefan_aus_hannover On

bind_rows() is actually what you're wanting and then you would have to deal with the NAs from the missing columns that are not in all 4 dataframes

df5 <- bind_rows(df1,df2,df3,df4)
df5[is.na(df5)] <- ''

If you're wanting whats in your image then you would just make a list of dataframes

listOfFrames <- list(df1,df2,df3,df4)