[R] Re: ifelse()
Ko-Kang Kevin Wang
kwan022 at stat.auckland.ac.nz
Wed Mar 26 12:47:57 CET 2003
Hi,
I've found a much better solution than using ifelse(). I found about
cut() from MASS4 Page 383, which actually does a better job .
On Wed, 26 Mar 2003, Ko-Kang Kevin Wang wrote:
> Date: Wed, 26 Mar 2003 23:20:04 +1200 (NZST)
> From: Ko-Kang Kevin Wang <kwan022 at stat.auckland.ac.nz>
> To: R Help <r-help at stat.math.ethz.ch>
> Subject: ifelse()
>
> Hi,
>
> I'm not sure if this can be done but..
>
> I know that with ifelse() I can do something like:
> ifelse(x <= 3, 1, 2)
> to go through each element in my vector x, and if x_i <= 3 substitute the
> number with 1 else with 2. Essentially I'll get a vector with 2 levels.
>
> Can I tweak it so I can get 3-levels? For example:
> if(x <= 3) then 1
> elseif(3 < x <= 4) then 2
> elseif(x > 4) then 3
>
>
--
Cheers,
Kevin
------------------------------------------------------------------------------
/* Time is the greatest teacher, unfortunately it kills its students */
--
Ko-Kang Kevin Wang
Master of Science (MSc) Student
SLC Tutor and Lab Demonstrator
Department of Statistics
University of Auckland
New Zealand
Homepage: http://www.stat.auckland.ac.nz/~kwan022
Ph: 373-7599
x88475 (City)
x88480 (Tamaki)
More information about the R-help
mailing list