Re: [R] efficient ways to dynamically grow a dataframe

2011-12-01 Thread R. Michael Weylandt
I'd also suggest you read circle 2 of the "R inferno" (just google it) which has some helpful tips on how to deal with these sorts of problems. Also, did you know that matrices can have column names and that rbind() preserves them? E.g., m <- matrix(1:6, 3); colnames(m) <- letters[1:2] print(m)

Re: [R] efficient ways to dynamically grow a dataframe

2011-12-01 Thread jim holtman
First, dataframes can be much slower than matrices, for example, if you are changing/accessing values a lot. I would suggest that you use a matrix since is seems that all your values are numeric. Allocate a large empty matrix to start (hopefully as large as you need). If you exceed this, you hav

[R] efficient ways to dynamically grow a dataframe

2011-12-01 Thread Matteo Richiardi
Hi, I'm trying to write a small microsimulation in R: that is, I have a dataframe with info on N individuals for the base-year and I have to grow it dynamically for T periods: df = data.frame( id = 1:N, x = ) The most straightforward way to solve the problem that came to my mind is to creat