AW: [R] constructing specially ordered factor

Khamenia, Valery V.Khamenia at biovision-discovery.de
Mon Oct 4 15:27:27 CEST 2004


Hi Petr,

Thank you for your reply.

> Factor <- function(f,n, decreasing=TRUE, ...) {
> ooo<-order(levels(factor(n)), decreasing=decreasing)
> my.order<-levels(factor(f))[ooo]
> factor(f, levels=my.order)
> }

it works incorrectly. Indeed, let's apply with your Factor:

  unames <- c("thousands", "units", "dozens", "hundreds", "thousands",
"dozens")
  u <- c(1000, 1,10,100, 1000, 10)
  Factor(unames, u)

the above produces the following output:

  [1] thousands units     dozens    hundreds  thousands dozens   
  Levels: units thousands hundreds dozens

where "dozens" > "hundreds"

---
Valery




More information about the R-help mailing list