[R] convert factor to numeric

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Jun 4 14:55:03 CEST 2003


See the FAQ, Q7.12.

On Wed, 4 Jun 2003, Philipp Pagel wrote:

> Every once in a while I need to convert a factor to a vector of numeric
> values. as.numeric(myfactor) of course returns a nice numeric vector of
> the indexes of the levels which is usually not what I had in mind:
...

It's done that way because that is how it is defined to work in S, and 
lots of code relies on it.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list