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

From: <Bill.Venables_at_csiro.au>
Date: Sat 08 Jan 2005 - 18:50:26 EST


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 Received on Sat Jan 08 17:59:37 2005

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:02:29 EST