Why rbind.data.frame function behaves differently in do.call

I have a question about do.call, rather strange

1. What am I trying to do

I am trying to link many data frames into one data frame, all data frames are in t3 list, you can see the pic below:

list variable t3

2. Methods

2.1 works alone

t4 <- do.call(rbind.data.frame, t3)

2.2 does not work

t4 <- rbind.data.frame(t3)

The error message below:

error message

3. Question

I think rbind.data.frame will behave the same if I remove do.call, why does it only work if I use do.call? Thanks in advance.

+4
source share
1 answer

The do.call(FUN, list) function was designed to receive the FUN input function along with the input of the list list . It applies a function to each item in the list and then aggregates the results.

In his appeal

 t4 <- rbind.data.frame(t3) 

You try rbind enumerate data frames when the rbind.data.frame function expects to enter only one data frame instead of t3 .

You can use rbind.data.frame without do.call if you want. Assuming that there are only 5 elements in the t3 list, then the following should work:

 t4 <- rbind.data.frame(t3[[1]], t3[[2]], t3[[3]], t3[[4]], t3[[5]]) 

As you can see, this will be tedious (and unreadable) quickly. This is the advantage of using do.call() .

+2
source

All Articles