Re: [Rd] Problem with table

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue, 27 Mar 2012 08:05:20 +0100

On 19/03/2012 17:01, Terry Therneau wrote:
> R version 2.14.0, started with --vanilla
>
> > table(c(1,2,3,4,NA), exclude=2, useNA='ifany')
> 1 3 4 <NA>
> 1 1 1 2
>
> This came from a local user who wanted to remove one particular response
> from some tables, but also wants to have NA always reported for data
> checking purposes.
> I don't think the above is what anyone would want.

You have not told us what you want!

Try

 > table(as.factor(c(1,2,3,4,NA)), exclude=2, useNA='ifany')

    1 3 4 <NA>
    1 1 1 1

Note carefully how 'exclude' is defined:

  exclude: levels to remove from all factors in ‘...’. If set to ‘NULL’,

           it implies ‘useNA="always"’.

As you did not specify a factor, 'exclude' was used in forming the 'levels'.

>
> PS.
> This is on a background of our local desires, which is to have the
> default action of the table command be
> to report NA, if present. (It's one of the only commands that we
> globally override at Mayo.) The user had
> added only the exclude=2 argument, and the useNA value is our default.
>
> The above makes this harder to do without rewriting the command
> wholesale, which is ok (we've done it before at
> various times in R and Splus) but we would avoid it if possible. Please
> no wars about whether this is the "right" decison or not, we've done it
> for 10+ years and quite firmly believe the extra robustness gained by
> having NA appear
> is worth the maintainance bother, correctness being paramount in medical
> research. We're not trying to convert anyone
> else, just get feedback on the best way to approach this.

Most likely, feed table() a factor with the properties you want.

>
> Terry T.
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Brian D. Ripley,                  ripley_at_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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue 27 Mar 2012 - 07:20:06 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 27 Mar 2012 - 13:30:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive