[R] Automatically naming subsets in a for loop

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Fri Jan 31 22:24:34 CET 2014


The standard way to do this is to use the cut function to define group categories, and then manipulate data in lists of subsets using lapply function and relatives. There are also tools such as the plyr package, data.table package, sqldf package, and the new dplyr package.

If you want more explicit help, then you really need to read the posting guide (e.g. no HTML email), and make a reproducible example (e.g. include some test data and an example calculation, even if you have to do it the long way with no loops).

http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On January 31, 2014 12:11:04 PM PST, denys <denys at uoguelph.ca> wrote:
>Hello,
>
>I'm trying to subet my data based on long/lat. I have written a for
>loop
>however I am not sure how to get R to name all my subsets different
>things.
>Here is my code so far...
>
>for(i in 0:31){
>latl=38+(i*1)
>latu=39+(i*1)
>for(j in 0:33){
>longl=(-72)+(j*1)
>longu=(-71)+(j*1)
>G$i$j<-subset(G, Lat>latl & Lat<latu & Long>longl & Long<longu)
>}
>}
>
>However this just freezes my computer. 
>Any help is appreciated!
>
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/Automatically-naming-subsets-in-a-for-loop-tp4684518.html
>Sent from the R help mailing list archive at Nabble.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
>and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list