Skip to content
Prev 32888 / 398513 Next

convert factor to numeric

Philipp Pagel <p.pagel at gsf.de> writes:
One reason is S compatibility, as Brian pointed out. But there is also
the point that you can *always* convert a factor to its underlying
integer values, but only *sometimes* convert the level names. Generally
we prefer code that fails more rarely...

as.numeric(as.character(f)) works too, although not quite as
efficiently as as.numeric(levels(f))[f].