From John_Hendrickx at yahoo.com  Wed Mar  5 18:10:38 2003
From: John_Hendrickx at yahoo.com (John_Hendrickx@yahoo.com)
Date: Thu Mar  6 12:25:46 2003
Subject: [Rd] modifying ftable to allow percentages (wishlist) (PR#2606)
Message-ID: <200303051710.h25HAcn9018168@pubhealth.ku.dk>

Full_Name: John Hendrickx
Version: 1.6.2
OS: Windows XP
Submission from: (NULL) (80.126.78.108)


(This is not a bug report but a request to add a feature to future versions of
R. Hope this is an appropriate place).

I'd like to suggest adding an option to ftable to allow percentages. It would be
easy to do and backwards compatible. Percentage tables are useful in educational
contexts, whereas lack of a simple method for calculating percentages gives an
incorrect impression of the maturity of R IMHO.

To add percentage tables to ftable, an option such as

pcnt=c("n", "row", "column", "total","gtotal")

could be added to ftable.default. Prior to the "y <- aperm" near the end of
ftable, the following lines would be added:

pcnt<-match.arg(pcnt)
if (pcnt!="n") {
    if (pcnt=="row")    {mrg2drop<-col.vars[length(col.vars)]}
    if (pcnt=="column") {mrg2drop<-row.vars[length(row.vars)]}
    if (pcnt=="total") 
{mrg2drop<-c(col.vars[length(col.vars)],row.vars[length(row.vars)])}
    if (pcnt=="gtotal") {mrg2drop<-0}
    x<-prop.table(x,i[-mrg2drop])*100
}

The pcnt option would default to "n" in which case nothing would happen, ftable
would work as presently. If pcnt="row" were used, percentages would sum to 100
over the last variable of col.vars for each row. For pcnt="column", percentages
would sum to 100 over the last variable of row.vars for each column. For
pcnt="total", percentages would sum to 100 for the last variable in row.vars and
col.vars, i.e. separately for each subtable. If pcnt="gtotal" were used, the
table would sum to 100 over the complete table.

One further modification would be needed in order to use percentages in
ftable.formula. Line 42 of ftable.formula, where ftable is called if
(inherits(edata, "ftable") is true would have to be changed to 

ftable(data, row.vars = rvars, col.vars = cvars, ...)

The ... argument would have to be added to pass pcnt= to ftable.default.

These seem to me to be minor changes that would add a useful functionality to R.
(Unless of course Guru[k] already has something much more sophisticated in the
pipeline). Would it be a problem to implement this in future versions of R?

Yours truly,
John Hendrickx


[Rd] modifying ftable to allow percentages (wishlist) (PR#2606)
John_Hendrickx@yahoo.com