Re: New codes() methods

About this list Date view Thread view Subject view Author view Other groups

Subject: Re: New codes() methods
From: Peter Dalgaard BSA (p.dalgaard@biostat.ku.dk)
Date: Thu 04 Nov 1999 - 21:34:56 EST


Message-ID: <x2aeou8p7j.fsf@blueberry.kubism.ku.dk>

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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Tue 04 Jan 2000 - 14:16:09 EST