[R] reverse lexicographic order

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sun Dec 14 23:49:34 CET 2003


Thomas W Blackwell <tblackw at umich.edu> writes:

> Murray  -
> 
> If you could guarantee that all of the email addresses have
> exactly one occurrence of the "@" character in them, then
> something like
....snip....

Otherwise, try something like this (I don't think we have a string
reversal function anywhere, do we?):

> mychar <- scan(what="")
1: I have some email addresses that I would like to sort in reverse
14: lexicographic order so that addresses from the same domain will be
25: grouped together. How might that be done?
32:
Read 31 items
>
>mychar[order(sapply(lapply(strsplit(mychar,""),rev),paste,collapse=""))]
 [1] "together."     "done?"         "I"             "I"
 [5] "lexicographic" "grouped"       "would"         "be"
 [9] "be"            "the"           "like"          "same"
[13] "some"          "reverse"       "have"          "email"
[17] "will"          "from"          "in"            "domain"
[21] "so"            "to"            "order"         "addresses"
[25] "addresses"     "that"          "that"          "that"
[29] "might"         "sort"          "How"



> > 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?
> >
> > Murray
> >
> > --
> > 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                                Fax 7 838 4155
> > Phone  +64 7 838 4773 wk    +64 7 849 6486 home    Mobile 021 1395 862
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> >
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list