[R] Coarsening Factors

From: Murray Jorgensen <maj_at_waikato.ac.nz>
Date: Fri 09 Sep 2005 - 07:59:58 EST


It is not uncommon to want to coarsen a factor by grouping levels together. I have found one way to do this in R:

> sites

  [1] F A A D A A B F C F A D E E D C F A E D F C E D E F F D B C Levels: A B C D E F
> regions <- list(I = c("A","B","C"), II = "D", III = c("E","F"))
> library(Epi)
> region <- Relevel(sites,regions)
> region

  [1] III I I II I I I III I III I II III III II I III I III
[20] II III I III II III III III II I I Levels: I II III

However this seems like using a sledgehammer to crack a nut. Can someone suggest a simpler way to do this task?

Murray Jorgensen

-- 
Dr Murray Jorgensen      http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: maj@waikato.ac.nz                                Fax 7 838 4155
Phone  +64 7 838 4773 wk     Home +64 7 825 0441   Mobile 021 1395 862

______________________________________________
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 Fri Sep 09 08:05:47 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:05 EST