Re: [Rd] sweep sanity checking?

From: Petr Savicky <savicky_at_cs.cas.cz>
Date: Thu, 12 Jul 2007 10:16:17 +0200

The suggestion sounds reasonable to me. Let me add that sweep is written to work even if MARGIN includes more than one dimension. To handle these cases correctly, the test may be replaced e.g. by

     if (check.margin && prod(dims[MARGIN])!=length(STATS)) {
       warning("length(STATS) != prod(dim(x)[MARGIN])")
     } else if (prod(dims[MARGIN]) %% length(STATS)!=0)
       warning("prod(dim(x)[MARGIN]) is not a multiple of length(STATS)")
or even by
     dimstat <- if (is.null(dim(STATS))) length(STATS) else dim(STATS)
     if (check.margin && any(dims[MARGIN]!=dimstat)) {
       warning("length(STATS) or dim(STAT) do not match dim(x)[MARGIN]")
     } else if (prod(dims[MARGIN]) %% length(STATS)!=0)
       warning("prod(dim(x)[MARGIN]) is not a multiple of length(STATS)")

Petr.

> Just an opinion from an R user: I think it's a sound idea. I use my own
> version of sweep with a stricter check: it stops if the vector is not
> exactly the right length.
>
> -- Tony Plate
>
> Ben Bolker wrote:
> > Ben Bolker <bolker <at> zoo.ufl.edu> writes:
> >
> >
> >> What would R-core think of the following 'enhanced'
> >> sweep?
> >>
> >
> > (now posted at
> > http://wiki.r-project.org/rwiki/doku.php?id=rdoc:base:sweep
> > )
> >
> > It always warns if dim(x)[MARGIN] is
> >



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 12 Jul 2007 - 08:26:52 GMT

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 Thu 12 Jul 2007 - 09:36:16 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.