Why do rbind () and do.call (rbind,) return different results?

I want to convert a list to a data frame with the following code:

ls<-list(a=c(1:4),b=c(3:6))
do.call("rbind",ls)

The result obtained by adding do.call is shown below. It returns an object data.frameas desired.

 do.call("rbind",ls)
  [,1] [,2] [,3] [,4]
a    1    2    3    4
b    3    4    5    6

However, if I use rbindit directly , it returns a list.

Why rbinddoes it behave differently in these two situations?

my.df<-rbind(ls)
str(ls)


 my.df
   a         b        
ls Integer,4 Integer,4

 str(ls)
List of 2
 $ a: int [1:4] 1 2 3 4
 $ b: int [1:4] 3 4 5 6
+4
source share
1 answer

do.call(rbind, ls) , Reduce(rbind, ls). , , , ls, ls ( 2 ).

"unlisting" , numeric. rbind , typeof, . rbind , . , matrix 1 2 list. , 1 , , ls , . rbind(ls, ls, ls) 3 2 .

+4

Source: https://habr.com/ru/post/1626456/


All Articles