Re: [R] How can I access the list argument within a "for" function call

From: jim holtman <jholtman_at_gmail.com>
Date: Sat, 22 Nov 2008 10:03:23 -0500

I am not sure exactly what you mean with your question. If you have a named list and want to access the 'name' within the 'for' along with the value, then you can do something like this:

for (i in names(myList)){

    value <- myList[[i]] # get the values     plot(values, main=paste("Plot of", i)) }

A little more clarification is need on your question.

On Fri, Nov 21, 2008 at 3:30 PM, Mike Rowe <miker_at_tethysbio.com> wrote:
> Greetings,
>
> I have been playing around with the R/Parallel package, which can farm out the computation of a for-loop among multiple worker processes. Each worker gets a chunk of the for-loop iterations; for example, if you have two workers and for(x in 1:1000){...}, one worker would typically get iterations 1:500, while the second does 501:1000.
>
> I would like to be able to preallocate matrices to capture the results within the for loop, on the first iteration. Is there a way to access the list argument of the "for" function programmatically from within the loop? I am referring to the for arguments shown on page 51 of the R Language Definition manual:
>
> "for"(var,list,expr)
>
> I think I have a work-around, but was curious whether this was possible...
>
> Thanks,
> Mike
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

______________________________________________
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.
Received on Sat 22 Nov 2008 - 15:08:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 24 Nov 2008 - 03:30:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive