Have a look at ?split Hadley
On Mon, Nov 9, 2009 at 10:41 AM, agm. <amur...@vt.edu> wrote: > > Hello, > > I'm trying to run a loop that will subset my data into specific sets by > regions and by race/ethnicity. I'm trying to do this fairly compactly, and > I cannot get this to work. > > A "simple" version of the code that I am trying to run is: > > names <- c("white", "black", "asian", "hispanic") > for(j in names){ > for(i in 1:9){ > names.cd[i].es.wash <- 1 > es.cd[i].names.w <- names.cd[i].es.wash +1 > } ; } > > I want the loop to create these variables so that I would have for example: > "white.cd1.es.wash" through "white.cd9.wash" and then the same for black, > hispanic, and asian > > (However, none of these variables have been created yet outside of the loop) > > > When I try to run this, I get the following error message: > > Error: unexpected symbol in: > "for(i in 1:9){ > names.cd[i].es.wash" > > Any idea what I am doing wrong? Thanks in advance for your help! I am > still trying to get my hands around this programming syntax > > -- > View this message in context: > http://old.nabble.com/Complicated-For-Loop-%28to-me%29-tp26269479p26269479.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. > -- http://had.co.nz/ ______________________________________________ R-help@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.