New codes() methods

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
04 Nov 1999 12:34:56 +0100


Jonathan Rougier <J.C.Rougier@durham.ac.uk> writes:


> Can I suggest a couple of new `codes' methods.  I know codes is a bit
> dodgy (at least, according to the comments in codes.factor), but for what
> it's worth I like to extract codes from data frames of factors, for which
> the following two functions (which operate recursively) are helpful:
> 
> "codes.default" <-
> function(x)
> {
>     if (is.list(x))
>       lapply(x, codes)
>     else
>       codes(factor(x))
> }
> 
> "codes.data.frame" <-
> function(x)
> {
>     row.names <- attr(x, "row.names")
>     data.frame(codes(as.list(x)), row.names = row.names)
> }

Looks quite nice. Two things have me worried, though:

1) do we really want to convert anything to factors? (try factor(rnorm(10000)))
2) if a dataframe contains a matrix, it gets converted to something
   with incompatible lengths
-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._