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

From: Oliver Bandel <oliver_at_first.in-berlin.de>
Date: Sun, 16 Nov 2008 16:37:36 +0000 (UTC)

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



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 16 Nov 2008 - 16:47:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 16 Nov 2008 - 17:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive