0

Apologies in advance if this is a duplicate question, but I can't find anything on this in the stack overflow archives.

I wrote a function that returns a zoo object (makeTrace1). In a second function (make2DHist), I call this function many times and so generate a list of dataframes (converted from the returned zoo objects). I would then like to rbind all these dataframes in my list together. I can rbind specific elements together so I could do this with a for loop, but is there a vectorized expression to rbind all the dataframes in the list together?

Here's my code:

make2DHist <- function() { v = list() times=4 for(i in 1:times) { vv = makeTrace1() v[[i]] = data.frame(Date=time(vv), vv, check.names = FALSE, row.names=NULL) } hhh = rbind(v[[1]], v[[2]]) <-----this works hhh2 = rbind(v[c(1:4)]) <-this does not work } m= make2DHist() 
3
  • I would go with do.call("rbind", lst) or using the data.table package rbindlist(lst) Commented Nov 24, 2014 at 23:34
  • 1
    @user20650 I knew I was forgetting something. Many thanks! Commented Nov 24, 2014 at 23:36
  • @Henrik Thank you, but this is probably not a duplicate. That question was a question of how to flatten a list. This question was about how to vectorize an rbind. I read that question before posting this one. Commented Nov 25, 2014 at 15:02

1 Answer 1

1
> x <- do.call(rbind, your_list_of_matrices_or_data_frames_here) 
Sign up to request clarification or add additional context in comments.

2 Comments

Also look at rbind.fill in the (very useful) plyr package.
Thank you! I'm new to R so these suggestions are really helpful.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.