How to append smaller DataFrame to another DataFra

2019-09-22 01:52发布

问题:

This question already has an answer here:

  • Combine two data frames by rows (rbind) when they have different sets of columns 13 answers

I have a single DataFrame that needs to be sent to a Quality Test API that should return another DataFrame.

But unfortunately the API is not accepting the DataFrame as a whole and hence I am slicing it row by row and sending it to the API.

Hence I am getting single row DataFrames with each request. Can someone tell me how I can keep appending these single rows to a larger Data Frame?

回答1:

You can append data frames to each other using bind_rows from the dplyr package.

df1 = data.frame(number = c(1, 2, 3, 4), 
                 name=c("Alice", "Bob", "Charlie", "Donna")
df2 = data.frame(number = c(5), name=c("Eve"))
df3 = bind_rows(df1, df2) #df3 has all five rows.