Re: [R] newbie question about index

From: Joris De Wolf <joris.dewolf_at_cropdesign.com>
Date: Fri 01 Sep 2006 - 08:45:04 GMT

what about:
b <- rbind(1*(a==1),1*(a==2),1*(a==3))

z s wrote:
> Hi,
>
> I am trying to convert a variable a = sample(1:3,100,rep = T) represents choices into a 3X100 dummy varible b with corresponding element set to 1 otherwise 0.
> eg.
>
> a: 1 3 2 1 2 3 1 1....
>
> b: 1 0 0 1 0 0 1 1..
> 0 0 1 0 1 0 0 0...
> 0 1 0 0 0 1 0 0...
>
> Is there something like b[a] =1 existing? I could not figure this out myself.
>
>
> ---------------------------------
> Mp3疯狂搜-新歌热歌高速下
> [[alternative HTML version deleted]]
>
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

confidentiality notice:
The information contained in this e-mail is confidential and...{{dropped}}



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Sep 01 20:01:34 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 07 Sep 2006 - 07:51:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.