Skip to content
Prev 106336 / 398506 Next

how to replace some objects?

you can use as.numeric(factor( )); in your example:
 > ex <- sample(letters[1:3], 10, T)
 > ex
  [1] "b" "b" "c" "b" "a" "a" "b" "b" "a" "a"

 > as.numeric(factor(ex))
  [1] 2 2 3 2 1 1 2 2 1 1

if the order is different, use levels:

 > as.numeric(factor(ex, levels=letters[3:1]))
  [1] 2 2 1 2 3 3 2 2 3 3

-------------------------------------------------------------------
Jacques VESLOT

CNRS UMR 8090
I.B.L (2?me ?tage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
-------------------------------------------------------------------

Zhang Jian a ?crit :