Re: [R] create dummy variables by for loop

2011-02-24 Thread Changbin Du
Thanks, Dimitri! It is really cool! On Thu, Feb 24, 2011 at 11:43 AM, Dimitri Liakhovitski < dimitri.liakhovit...@gmail.com> wrote: > If your ack$ID variable is numeric, you could first turn it into a factor: > > myfactor = as.factor(ack$ID) > > And then use model.matrix to create dummy variables

Re: [R] create dummy variables by for loop

2011-02-24 Thread Dimitri Liakhovitski
If your ack$ID variable is numeric, you could first turn it into a factor: myfactor = as.factor(ack$ID) And then use model.matrix to create dummy variables: mydummies = model.matrix(~myfactor)[, -1] You'll get as many dummy variables as values you have in ack$ID - minus 1 (for the reference lev

Re: [R] create dummy variables by for loop

2011-02-24 Thread Changbin Du
Thanks, David! On Thu, Feb 24, 2011 at 11:30 AM, David Winsemius wrote: > > On Feb 24, 2011, at 1:23 PM, Changbin Du wrote: > > HI, Dear R community, >> >> I try to create 100 dummy variables like the following: >> >> ack$id_1 <- (ack$ID==1)*1 >> ack$id_2 <- (ack$ID==2)*1 >> .. >> . >> ack$id_100

Re: [R] create dummy variables by for loop

2011-02-24 Thread David Winsemius
On Feb 24, 2011, at 1:23 PM, Changbin Du wrote: HI, Dear R community, I try to create 100 dummy variables like the following: ack$id_1 <- (ack$ID==1)*1 ack$id_2 <- (ack$ID==2)*1 .. . ack$id_100 <- (ack$ID==100)*1 I used the following codes: for(i in 1:100){ ack$id_[i] <- (ack$

Re: [R] create dummy variables by for loop

2011-02-24 Thread Changbin Du
Thanks to all, appreciated! On Thu, Feb 24, 2011 at 11:18 AM, Jonathan P Daily wrote: > See inline below. > -- > Jonathan P. Daily > Technician - USGS Leetown Science Center > 11649 Leetown Road > Kearneysville WV, 25430 > (304) 724-4480 > "Is the room still a

Re: [R] create dummy variables by for loop

2011-02-24 Thread Jonathan P Daily
See inline below. -- Jonathan P. Daily Technician - USGS Leetown Science Center 11649 Leetown Road Kearneysville WV, 25430 (304) 724-4480 "Is the room still a room when its empty? Does the room, the thing itself have purpose? Or do we, what's the word... imbue i