Shane,
Does this work?
# Your simulated data
subject=1:1000
treat=rbinom(1*1000,1,.13)
gender=rbinom(1*1000,1,.5)
eth=runif(1*1000, min=1, max=4)
cogat=rnorm(1*1000, 100, 16)
map=rnorm(1*1000, 200, 9)
growth=0
simtest=data.frame (subject=subject, treat=treat, gender=gender,
eth=round(eth,digits=
quot;
Cc:
Sent: Tuesday, April 12, 2011 2:32 PM
Subject: Re: [R] Converting a categorical variable to multiple
dichotemousvariables
> hi:
> here is one solution:
>
> cat<-as.factor(c(1,1,3,2,4))
> model.matrix(~cat-1,cat)
>
> cbind(cat,model.matrix(~cat-1,cat))
Hi Shane,
An alternative is:
cat<-as.factor(c(1,1,3,2,4))
outer(cat, levels(cat), "==")+0
Cheers,
Pablo
- Original Message -
From: "andrija djurovic"
To: "Shane Phillips"
Cc:
Sent: Tuesday, April 12, 2011 2:32 PM
Subject: Re: [R] Converting a
3 matches
Mail list logo