[R] recoding variables

Philipp Pagel p.pagel at gsf.de
Thu Mar 11 16:27:32 CET 2004


	Hi!

> using R, and I'm trying to figure out how to recode a continuous
> variable to make it into an ordinal variable with 3 categories.

You are looking for cut():

> a <- runif(15)

> a
 [1] 0.19109987 0.78808597 0.78458256 0.31355035 0.02076274 0.82287287 0.75260382 0.82627690 0.14775167
[10] 0.59427620 0.12314764 0.44151537 0.05123785 0.88879744 0.25552054

> b = cut(a, breaks=c(0, 0.33, 0.66, 1), labels=c('low', 'medium', 'high'))

> b
 [1] low    high   high   low    low    high   high   high   low medium low    medium low    high   low
Levels: low medium high

cu
	Philipp


-- 
Dr. Philipp Pagel                            Tel.  +49-89-3187-3675
Institute for Bioinformatics / MIPS          Fax.  +49-89-3187-3585
GSF - National Research Center for Environment and Health
Ingolstaedter Landstrasse 1
85764 Neuherberg, Germany
http://mips.gsf.de/~pagel




More information about the R-help mailing list