From: Peter Dalgaard BSA (email@example.com)
Date: Wed 04 Jun 2003 - 23:49:48 EST
Philipp Pagel <firstname.lastname@example.org> writes:
> But I just can't believe there is no R function to do this in a more
> readable way. Actually, the behaviour of as.numeric() doesn't strike me
> as very intuitive. I'm sure it has been implemented that way for a
> reason - but what is it?
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].
-- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (email@example.com) FAX: (+45) 35327907
______________________________________________ Rfirstname.lastname@example.org mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
This archive was generated by hypermail 2.1.3 : Tue 01 Jul 2003 - 09:11:52 EST