Re: [R] R for loop question

2008-05-20 Thread jim holtman
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 < [EMAIL PROTECTED]> wrote: > He

Re: [R] R for loop question

2008-05-20 Thread Erik Iverson
Take a look at ?assign Juan Manuel Barreneche wrote: I had to do the same thing many times, i usually use a combination of the functions "eval", "parse" and "sprinf", as below: k <- 1 for (i in 1:length(stats$hour)) { eval(parse(text=sprintf("x%s <- dataset[%s,(3:15)]", i, k))) k <- k+1

Re: [R] R for loop question

2008-05-20 Thread Juan Manuel Barreneche
I had to do the same thing many times, i usually use a combination of the functions "eval", "parse" and "sprinf", as below: k <- 1 for (i in 1:length(stats$hour)) { eval(parse(text=sprintf("x%s <- dataset[%s,(3:15)]", i, k))) k <- k+1 } what it does is: eval(parse(text=STRING)) is a way to

Re: [R] R for loop question

2008-05-20 Thread Erik Iverson
Douglas - To answer your question directly, use perhaps combination of ?assign and ?paste. In general, you usually do not have to do this sort of thing, but can use one of the apply family of functions (apply, sapply, lapply, mapply) to do whatever you want with shorter, cleaner code and few

[R] R for loop question

2008-05-20 Thread Douglas M. Hultstrand
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