[R] Changing values (factors) does not change levels of that value?!

Oliver Bandel oliver at first.in-berlin.de
Sun Nov 16 17:37:36 CET 2008


Philipp Pagel <p.pagel <at> wzw.tum.de> writes:

[...]
> 
> foo$bar <- factor(foo$bar)

This was my first attemot, before posting here,
and it somehow did not worked... 
...now it works.... so I maybe was too tired,
when trying it and messed something up. :(



[...] 
> > x <- factor(c(0,1,3,4,5,7))
> > x
> [1] 0 1 3 4 5 7
> Levels: 0 1 3 4 5 7
> > as.numeric(x)
> [1] 1 2 3 4 5 6

I know, and that's the reason why I first used 
as.vector() before passing the results to as.numeric().

Without as.vector() one get's the int-representation of the factors,
and not the values of the column.

Ciao,
   Oliver



More information about the R-help mailing list