[R] Complicated For Loop (to me)

agm. amurray at vt.edu
Mon Nov 9 17:41:57 CET 2009


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.




More information about the R-help mailing list