From ripley at stats.ox.ac.uk  Sat Jan  8 10:40:30 2005
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Sat Jan  8 10:40:43 2005
Subject: [Rd] as.data.frame.table and the name "Freq"
In-Reply-To: <B998A44C8986644EA8029CFE6396A9240AB129@exqld2-bne.qld.csiro.au>
References: <B998A44C8986644EA8029CFE6396A9240AB129@exqld2-bne.qld.csiro.au>
Message-ID: <Pine.LNX.4.61.0501080939560.797@gannet.stats>

No sooner said that done.
It _is_ nice to see code with a suggested enhancement.

On Sat, 8 Jan 2005 Bill.Venables@csiro.au wrote:

> May I suggest that the method as.data.frame.table not have the name
> "Freq" hardwired as the response name?  This is a problem if "Freq" is
> already the name of a stimulus factor.
>
> Here is the existing function:
>
> as.data.frame.table <- function (x, row.names = NULL, optional = FALSE,
> ...) {
>    x <- as.table(x)
>    data.frame(do.call("expand.grid", dimnames(x)), Freq = c(x),
>        row.names = row.names)
> }
>
> My suggested fix is
>
> as.data.frame.table <-
> function (x, row.names = NULL, optional = FALSE, responseName = "Freq",
> ...) {
>    x <- as.table(x)
>    ex <- Quote(data.frame(do.call("expand.grid", dimnames(x)), Freq =
> c(x),
>        row.names = row.names))
>    names(ex)[3] <- responseName
>    eval(ex)
> }
>
> This should be no slower and should break no existing code.
>
> Bill Venables,
>
> ______________________________________________
> R-devel@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


[Rd] as.data.frame.table and the name "Freq"
Prof Brian Ripley