Re: [R] conditional replacement

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Wed 24 May 2006 - 16:24:11 EST


Hi

if speed is critical you can use

(x>=30&x<=60)*x+(x<30)*30+(x>60)*60

HTH
Petr

On 23 May 2006 at 16:34, Rogerio Porto wrote:

From:           	"Rogerio Porto" <rdporto1@terra.com.br>
To:             	"Sachin J" <sachinj.2006@yahoo.com>, <R-help@stat.math.ethz.ch>
Date sent:      	Tue, 23 May 2006 16:34:04 -0300
Subject:        	Re: [R] conditional replacement

> Sachin,
>
> there's another slower but more flexible way than Gabor's solution:
>
> ifelse(x<30,30,ifelse(x>60,60,x))
>
> HTH,
>
> Rogerio.
> ----- Original Message -----
> From: "Sachin J" <sachinj.2006@yahoo.com>
> To: <R-help@stat.math.ethz.ch>
> Sent: Tuesday, May 23, 2006 3:40 PM
> Subject: [R] conditional replacement
>
>
> > Hi
> >
> > How can do this in R.
> >
> > >df
> >
> > 48
> > 1
> > 35
> > 32
> > 80
> >
> > If df < 30 then replace it with 30 and else if df > 60 replace it
> > with
> > 60. I have a large dataset so I cant afford to identify indexes and
> > then replace.
> > Desired o/p:
> >
> > 48
> > 30
> > 35
> > 32
> > 60
> >
> > Thanx in advance.
> >
> > Sachin
> > __________________________________________________
> >
> >
> >
> > [[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
> >
>
> ______________________________________________
> 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

Petr Pikal
petr.pikal@precheza.cz



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 Received on Wed May 24 16:31:38 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 Wed 24 May 2006 - 18:10:18 EST.

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