[R] Managing output

Erik Iverson eiverson at NMDP.ORG
Wed Aug 26 21:27:14 CEST 2009


How about ?append, but R is vectorized, so why not just

result_list <- 2*item^2 , or for more complicated tasks, the apply/sapply/lapply/mapply family of functions?

In general, the "for" loop construct can be avoided so you don't have to think about messy indexing.  What exactly are you trying to do? 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Noah Silverman
Sent: Wednesday, August 26, 2009 2:20 PM
To: r help
Subject: [R] Managing output

Hi,


Is there a way to build up a vector, item by item.  In perl, we can 
"push" an item onto an array.  How can we can do this in R?
I have a loop that generates values as it goes.  I want to end up with a 
vector of all the loop results.

In perl it woud be:

for(item in list){
     result <- 2*item^2 (Or whatever formula, this is just a pseudo example)
     Push(@result_list, result)  (This is the step I can't do in R)
}


Thanks!

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list