Re: [R] R for loop question

From: jim holtman <jholtman_at_gmail.com>
Date: Tue, 20 May 2008 16:44:04 -0400

Consider using a 'list' instead of creating a lot of objects that you then have to manage:

x <- lapply(1:length(stats$hour), function(.indx) dataset[.indx, 3:15])

You can then access the data as x[[1]], ...

On Tue, May 20, 2008 at 12:58 PM, Douglas M. Hultstrand < dmhultst_at_metstat.com> wrote:

> Hello,
>
> I am trying to assign a variable name (x1,x2,x3...) in a loop statement
> that is based on a counter (counter is based on the number of hours within
> the datafile). The x1,x2 data will later be called for plotting the data.
> Below is a clip of the for loop I am using, any suggestions?
>
> k = 1
> for (i in 1:length(stats$hour)) {
> "x(i)" = dataset[k,(3:15)]
> k = k+1
> }
>
> Thanks,
> Doug
>
> --
> ---------------------------------
> Douglas M. Hultstrand, MS
> Senior Hydrometeorologist
> Metstat, Inc. Windsor, Colorado
> voice: 970.686.1253
> email: dmhultst_at_metstat.com
> web: http://www.metstat.com
>
> ______________________________________________
> 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<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 you are trying to solve?

	[[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.
Received on Tue 20 May 2008 - 20:47:03 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 Tue 20 May 2008 - 21:30:59 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