thanks for those ideas! I'm sure I will learn a lot be fooling around with them.
Cheers,
Murray
Duncan Murdoch wrote:
On Mon, 15 Dec 2003 10:08:31 +1300, you wrote:
Hi all,
I have some email addresses that I would like to sort in reverse lexicographic order so that addresses from the same domain will be grouped together. How might that be done?
I'm not sure this is what you want, but this function sorts a character vector by last letters, then 2nd last, 3rd last, and so on:
revsort <- function(x,...) { x[order(unlist(lapply(strsplit(x,''), function(x) paste(rev(x),collapse=''))),...)] }
revsort(as.character(1:20))
[1] "10" "20" "1" "11" "2" "12" "3" "13" "4" "14" "5" "15" "6"
"16" "7" [16] "17" "8" "18" "9" "19"
The ... args are given to order(), so na.last=FALSE and decreasing=TRUE are possibilities.
Duncan Murdoch
-- Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html Department of Statistics, University of Waikato, Hamilton, New Zealand Email: [EMAIL PROTECTED] Fax 7 838 4155 Phone +64 7 838 4773 wk +64 7 849 6486 home Mobile 021 1395 862
______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
