[R] Complicated For Loop (to me)

2009-11-09 Thread agm.
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

Re: [R] Complicated For Loop (to me)

2009-11-09 Thread hadley wickham
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

Re: [R] Complicated For Loop (to me)

2009-11-09 Thread agm.
I've looked through ?split and run all of the code, but I am not sure that I can use it in such a way to make it do what I need. Another suggestion was using lists, but again, I am sure that the process can do what I need, but I am not sure it would work with so many observations. I might have

Re: [R] Complicated For Loop (to me)

2009-11-09 Thread Don MacQueen
You're looking for the assign() function. See the first example in the help page for assign() Something like assign( paste( j,'.cd',i,'es.wash',sep='') , 1 ) instead of names.cd[i].es.wash - 1 paste() assembles the name as a character string, and then assign() assigns a value to a

Re: [R] Complicated For Loop (to me)

2009-11-09 Thread John Kane
think that you could just put all your subsets into a list and use lapply but I'm simply guessing without seeing the data. --- On Mon, 11/9/09, agm. amur...@vt.edu wrote: From: agm. amur...@vt.edu Subject: Re: [R] Complicated For Loop (to me) To: r-help@r-project.org Received: Monday

Re: [R] Complicated For Loop (to me)

2009-11-09 Thread jim holtman
Since you did not follow the posting and provide data, here is a way that you can split by race region and perform operations on each subset of the data frame: # test data n - 4500 x - data.frame(race=sample(c('a','b','c'), n, TRUE), + region=sample(1:9, n, TRUE),

Re: [R] Complicated For Loop (to me)

2009-11-09 Thread agm.
Subject: Re: [R] Complicated For Loop (to me) To: r-help@r-project.org Received: Monday, November 9, 2009, 3:18 PM I've looked through ?split and run all of the code, but I am not sure that I can use it in such a way to make it do what I need.  Another suggestion was using lists, but again, I

Re: [R] Complicated For Loop (to me)

2009-11-09 Thread David Winsemius
seeing the data. --- On Mon, 11/9/09, agm. amur...@vt.edu wrote: From: agm. amur...@vt.edu Subject: Re: [R] Complicated For Loop (to me) To: r-help@r-project.org Received: Monday, November 9, 2009, 3:18 PM I've looked through ?split and run all of the code, but I am not sure that I can use

Re: [R] Complicated For Loop (to me)

2009-11-09 Thread Petr PIKAL
. amur...@vt.edu Subject: Re: [R] Complicated For Loop (to me) To: r-help@r-project.org Received: Monday, November 9, 2009, 3:18 PM I've looked through ?split and run all of the code, but I am not sure that I can use it in such a way to make it do what I need. Another suggestion