r - Collecting an unknown number of results in a loop -
what idiomatic way collect results in loop in r if number of final results not known beforehand? here's toy example: results = vector('integer') i=1l while (i < bigbigbignumber) { if (somecondition(i)) results = c(results, i) = i+1 } results the problem example (i assume) have quadratic complexity vector needs re-allocated @ every append. (is correct?) i'm looking solution avoids this. i found filter , requires pre-generating 1:bigbigbignumber want avoid conserve memory. (question: for (i in 1:n) pre-generate 1:n , keep in memory?) i make linked list this: results = list() i=1l while (i < bigbigbignumber) { if (somecondition(i)) results = list(results, i) = i+1 } unlist(results) (note not concatenation. it's building structure list(list(list(1),2),3) , flattening unlist .) is there better way this? idiomatic way that's typically used? (i new r.) i'm looking suggestion on how tackle type of problem. sugge...