Sam Buttrey brought to my attention the argument left.include of cut(),
which allows you to specify bins closed on the left. Thanks Sam.
Then, in answer to Frank Lawrence's question,
x <- seq(0,2,0.1)
c(0,1,2)[cut(x,breaks=c(-Inf,0.5,1.5,Inf),factor=T,left.include=T)]
Nick Ellis
CSIRO Marine Research mailto:Nick.Ellis@csiro.au
PO Box 120 ph +61 (07) 3826 7260
Cleveland QLD 4163 fax +61 (07) 3826 7222
Australia http://www.marine.csiro.au
> -----Original Message-----
> From: Frank Lawrence [mailto:Cougar@psu.edu]
> Sent: Friday, March 21, 2003 3:35 AM
> To: s-news@lists.biostat.wustl.edu
> Subject: [S] recode
>
>
> I would like to know how to quickly recode multiple variables. In one
> problem I have, I need to recode the data in a 600 x 200 data
> frame so that
> values less than 0.5 are scored 0, those equal to or greater
> than 1.5 are
> scored 2, and those in between are scored 1. Using loops
> seems to take a
> very long time. Is there a more efficient way to accomplish
> the recode?
> WIN 2k, Splus 6.1
>
>
> Respectfully,
> Frank R. Lawrence
>
|