[Rd] ftable.formula

William Dunlap wdunlap at tibco.com
Fri Jan 27 02:06:39 CET 2012


Put the formula first in the argument list or label
the data argument data= and put the formula after it
if you want to use the formula method for ftable.

  > ftable(data=UCBAdmissions, Gender + Admit ~ Dept)
       Gender     Male            Female
       Admit  Admitted Rejected Admitted Rejected
  Dept
  A                512      313       89       19
  B                353      207       17        8
  C                120      205      202      391
  D                138      279      131      244
  E                 53      138       94      299
  F                 22      351       24      317

The array method for ftable appears to ignore a formula.
It expects a row.vars and/or col.vars argument:
  > ftable(UCBAdmissions, nonSense ~ more + nonSense)
                  Dept   A   B   C   D   E   F
  Admit    Gender
  Admitted Male        512 353 120 138  53  22
           Female       89  17 202 131  94  24
  Rejected Male        313 207 205 279 138 351
           Female       19   8 391 244 299 317

Since most generic functions and methods have ... in the
argument list you don't get warned about supplying
arguments that the method does not expect.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> -----Original Message-----
> From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r-project.org] On Behalf Of Timothy Bates
> Sent: Thursday, January 26, 2012 3:17 PM
> To: r-devel at stat.math.ethz.ch
> Subject: Re: [Rd] ftable.formula
> 
> At least this is correct :-)
> 
>  ftable(UCBAdmissions, Dept ~ Gender + Admit)
> 
> But yes: the formula
> ftable(UCBAdmissions, Gender + Admit ~ Dept)
> 
> should see "The left and right hand side of formula specify the column and row variables,
> respectively"
> 
> # demo of right-hand side bug
> 
> ftable(UCBAdmissions, Gender + Admit ~ Dept) # "Dept" should be in the rows...
>                 Dept   A   B   C   D   E   F
> Admit    Gender
> Admitted Male        512 353 120 138  53  22
>          Female       89  17 202 131  94  24
> Rejected Male        313 207 205 279 138 351
>          Female       19   8 391 244 299 317
> 
> 
> Also, the example appears not to be a correct use of the "." shortcut.
> 
> x <- ftable(Survived ~ ., data = Titanic)
> # Error in ftable.formula(Survived ~ ., data = Titanic) :
> #  cannot use dots in formula with given data
> 
> Also "Survived" should be "survived"
> And in this example, all vars should be lower-case
> 
> ftable(Sex ~ Class + Age, data = x)
> 
> t
> 
> On 26 Jan 2012, at 22:31, Brett Presnell wrote:
> > From reading the documentation for ftable.formula, I expected that the
> > following two calls to ftable would produce the same results:
> >
> > data(UCBAdmissions)
> > ftable(UCBAdmissions, row.vars = "Dept", col.vars = c("Gender", "Admit"))
> > ftable(UCBAdmissions, Gender + Admit ~ Dept)
> >
> > Is this a bug or the intended behavior?  I prefer the formula interface,
> > so I would be happiest if the output was the same for the two calls.
> > However, if this is the intended behavior, then I think that the
> > documentation should be clearer on this point.
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list