Hi

as far as result of operation is logical vector you can change it to numeric by 
simple multyplying by 1 or adding 0. It is treated as 0 when FALSE and 1 when 
TRUE.

Regards
Petr

From: Tasnuva Tabassum [mailto:t.tasn...@gmail.com]
Sent: Wednesday, February 27, 2013 10:16 AM
To: PIKAL Petr; Berend Hasselman
Subject: Re: [R] Merging value labels into indicator variable.

Yes, I tried them all. They worked well. I think when I have a little complex 
case where NAM has values 1,2,3,22,88,101 and I need to make an indicator 
taking value 1 for NAM=22 or NAM=88 or NAM=101; I may use Var001<-ifelse(NAM 
%in% c(22,88,101),1,0).  Or, I can use Var001<-1*NAM %in% c(22,88,101).

On Wed, Feb 27, 2013 at 1:20 PM, PIKAL Petr 
<petr.pi...@precheza.cz<mailto:petr.pi...@precheza.cz>> wrote:
Hi

can not resist

Var001 <- (NAM>=7 & NAM<=9)*1

Regards
Petr

> -----Original Message-----
> From: r-help-boun...@r-project.org<mailto:r-help-boun...@r-project.org> 
> [mailto:r-help-bounces@r-<mailto:r-help-bounces@r->
> project.org<http://project.org>] On Behalf Of Tasnuva Tabassum
> Sent: Tuesday, February 26, 2013 7:03 PM
> To: Berend Hasselman
> Cc: R help
> Subject: Re: [R] Merging value labels into indicator variable.
>
> Thanx all, I found my answer. I prefer Peter's second solution.
>
>
> On Tue, Feb 26, 2013 at 11:59 PM, Berend Hasselman 
> <b...@xs4all.nl<mailto:b...@xs4all.nl>>
> wrote:
>
> >
> > On 26-02-2013, at 18:45, Tasnuva Tabassum 
> > <t.tasn...@gmail.com<mailto:t.tasn...@gmail.com>>
> wrote:
> >
> > > I have a vaiable named NAM having value : 1,2,3,4,5,6,7,8,9.  I
> want
> > > to make an indicator variable that will take value 1 if NAM=7 or
> > > NAM=8 or NAM=9. How can I do that?
> > > I usually do: Var001<- ifelse(NAM==7,1,0) for the simplest case.
> >
> >
> > How about
> >
> > Var001<- ifelse(NAM>=7 &  NAM<=9,1,0)
> >
> >
> > Berend
> >
>
>       [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org<mailto:R-help@r-project.org> 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.


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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.

Reply via email to