Martin Maechler <[EMAIL PROTECTED]> writes:

>     >> as.numeric (levels (y)[as.numeric (y)])
>     NaLi> [1] 1 3 1
> 
>     NaLi> which is a bit awkward.

> as.numeric(as.character(y)) !
> 
> {in some cases you might consider using as.integer() instead of as.numeric()}

Better to convert first and then index:

as.numeric(levels(y))[y] 

The speed gain is only going to be visible on huge vectors, though.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED])             FAX: (+45) 35327907

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to