s-news
[Top] [All Lists]

Re: [S] creat dummy variables

To: "Jing (Jane) Xu" <jxu@athena.biostat.jhsph.edu>
Subject: Re: [S] creat dummy variables
From: Alan Zaslavsky <zaslavsk@hcp.med.harvard.edu>
Date: Thu, 25 Jun 1998 17:19:15 -0400 (EDT)
Cc: s-news@wubios.wustl.edu
In-reply-to: <Pine.GSO.3.96.980625154152.3822A-100000@athena.biostat.jhsph.edu>
Sender: owner-s-news@wubios.wustl.edu
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

<Prev in Thread] Current Thread [Next in Thread>