[R] coarsening levels problem
Murray Jorgensen
maj at waikato.ac.nz
Sat Nov 17 22:28:26 CET 2012
Greetings from New Zealand.
I hope that my difficulties are clear from the following output. Ideas
gratefully received!
Murray Jorgensen
cc <- scan()
3000 3500 2500 2500 3000 3000 3000 3000 3000 2000
2000 2000 2000 4800 3000 4500 3000 2000 2000 4400
3000 3000 2500 3000 3000 2000 3000 2000 2000 2000 3000 2000
cc <- as.factor(cc)
> cc
[1] 3000 3500 2500 2500 3000 3000 3000 3000 3000 2000
[11] 2000 2000 2000 4800 3000 4500 3000 2000 2000 4400
[21] 3000 3000 2500 3000 3000 2000 3000 2000 2000 2000
[31] 3000 2000
Levels: 2000 2500 3000 3500 4400 4500 4800
> engroups <- list(L2 = 2000, L2.5 = 2500, L3 = 3000,
+ large = c(3500,4400,4500,4800))
> levels(cc) <- engroups
> cc
[1] L3 large L2.5 L2.5 L3 L3 L3 L3 L3
[10] L2 L2 L2 L2 large L3 large L3 L2
[19] L2 large L3 L3 L2.5 L3 L3 L2 L3
[28] L2 L2 L2 L3 L2
Levels: L2 L2.5 L3 large
reg <-
structure(c(6L, 6L, 1L, 7L, 1L, 1L, 1L, 5L, 2L, 1L, 6L, 3L, 1L,
1L, 7L, 1L, 4L, 1L, 1L, 1L, 1L, 1L, 7L, 6L, 6L, 1L, 1L, 1L, 1L,
6L, 2L, 7L), .Label = c(" auckland", " christchurch", " hb",
" manawatu", " taranaki", " waikato", " wellington"), class = "factor")
> reg
[1] waikato waikato auckland
[4] wellington auckland auckland
[7] auckland taranaki christchurch
[10] auckland waikato hb
[13] auckland auckland wellington
[16] auckland manawatu auckland
[19] auckland auckland auckland
[22] auckland wellington waikato
[25] waikato auckland auckland
[28] auckland auckland waikato
[31] christchurch wellington
7 Levels: auckland christchurch hb ... wellington
> rg2 <- list(akl = c("auckland"), other = c("christchurch",
+ "hb", "manawatu", "taranaki", "waikato", "wellington"))
> levels(reg) <- rg2
> reg
[1] <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
[11] <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
[21] <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
[31] <NA> <NA>
Levels: akl other
--
Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: maj at waikato.ac.nz majorgensen at ihug.co.nz Fax 7 838 4155
Phone +64 7 838 4773 wk Home +64 7 825 0441 Mobile 021 0200 8350
More information about the R-help
mailing list