Say, I have a vector and a function with one argument which returns a data.frame. I want to apply the function to each element of the vector and combine the results to one big data.frame.
I've got the working command below with lapply and rbind. But it looks to me a little bit "unnatural". Is there a better, more clear way? I've got some ideas with plyr but I would like to avoid plyr because I would like to use dplyr instead.
my_vector <- c(1,2,3)
my_function <- function(a){
unif <- runif(a)
norm <- rnorm(a)
return(data.frame(unif=unif, norm=norm))
}
as.data.frame(do.call(rbind,(lapply(my_vector, my_function))))