AW: [R] constructing specially ordered factor

Khamenia, Valery V.Khamenia at
Mon Oct 4 15:16:28 CEST 2004

Hi Dimitris,

thank you for your reply, 

> does the following work in your data:
> levs <- unique.default(Names)
> factor(Names, levs[order(unique.default(Weights))])

your solution is really shorter, but has two issues to be 
meant here:

1. "unique.default" is applied twice, what might 
   be a bit expensive for strings.

2. your solution brings an implicit prerequisit on 
  "unique.default". Indeed, "unique.default" should 
  preserve the same order for output both working 
  with strings and with numbers. In other words, 
  correspondence must be kept by "unique.default".
  If "unique.default" implementation uses (or will use) 
  lexicographic strings sorting for acceleration
  then this approach fails.


More information about the R-help mailing list