Re: [R] sorting factor levels by data frequency of levels

2007-11-19 Thread Greg Snow
?reorder Try: > newstate <- reorder(state,state, length) Or > newstate <- reorder(state,state, function(x) -length(x) ) Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 > -Original Message- > From:

Re: [R] sorting factor levels by data frequency of levels

2007-11-17 Thread Jim Lemon
Shoaaib Mehmood wrote: > using an example from r online help > > >>state <- c("tas", "sa", "qld", "nsw", "nsw", "nt", "wa", "wa", > > "qld", "vic", "nsw", "vic", "qld", "qld", "sa", "tas", > "sa", "nt", "wa", "vic", "qld", "nsw", "nsw", "wa", > "sa", "act", "nsw", "vic", "vic", "act"

Re: [R] sorting factor levels by data frequency of levels

2007-11-16 Thread Dimitris Rizopoulos
one way is the following: tb <- table(state) statefac <- factor(state, levels = names(tb[order(tb, decreasing = TRUE)])) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvo