Re: [S] creat dummy variables

Alan Zaslavsky (zaslavsk@hcp.med.harvard.edu)
Thu, 25 Jun 1998 17:19:15 -0400 (EDT)


I think you want something like this:

diag(max(f)+1)[f+1,-1]

where the -1 drops the first of the dummy variables, but you can take your
pick of which to drop.

Or if you want to be a bit more in line with usual modeling stuff, you can
do

contr.treatment(max(f)+1)[f+1,]

which opens up the possibility of other contrast matrix codings. You could
even use the model.matrix() function!

On Thu, 25 Jun 1998, Jing (Jane) Xu wrote:

>
> Hi, everyone,
>
> Is there a simple way to create (n-1) dummy variables from a single
> variable which takes values 0,1,...,n-1?
>
> Say, I have a variable f like:
> f
> 0
> 2
> 1
> 2
> 0
> how can I get something like:
> d1 d2
> 0 0
> 1 1
> 1 0
> 1 1
> 0 0
>
> Any help would be greatly appreciated!
>
> Jane
>
>
> -----------------------------------------------------------------------
> This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
> send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
> message: unsubscribe s-news
>

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news