From p.dalgaard@biostat.ku.dk  Thu Nov  4 11:34:56 1999
From: p.dalgaard@biostat.ku.dk (Peter Dalgaard BSA)
Date: 04 Nov 1999 12:34:56 +0100
Subject: New codes() methods
In-Reply-To: Jonathan Rougier's message of "Thu, 4 Nov 1999 11:23:44 +0000 (GMT)"
References: <Pine.GSO.3.96.991104110533.16942A-100000@laplace>
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


New codes() methods
Peter Dalgaard BSA