Understanding unlisting matrix using do.call

188 views Asked by At

I was searching for some approaches to unlist matrices and I think the most efficient and simplest one is

do.call(rbind, matrix_to_unlist). I tried it and it works but I have no idea why. rbind() function is designed to add a row to matrix/data frame so how is this possible to work ? Could you please explain to me what exactly do.call() is doing with rbind() function that in output we get matrix unlisted ?

1

There are 1 answers

0
Neeraj On

If you check the help file of do.call, it reads

do.call constructs and executes a function call from a name or a function and a list of arguments to be passed to it.

So, let suppose, you have

matrices_in_list <- list(matrix_a, matrix_b, ...)

so, when you run do.call(rbind, matrices_in_list), then it is equivalent to:

rbind(matrix_a, matrix_b, ...)

You can call cbind to bind your matrices by column.