[Rd] bug in by.data.frame, R-2.6.1 (PR#10506)
ripley at stats.ox.ac.uk
ripley at stats.ox.ac.uk
Wed Dec 19 07:20:14 CET 2007
It transpires that package survey relies on the current behaviour (which
is not new in 2.6.1: R 2.0.0 did it).
The suggested fix is reasonable if 'data' was originally a data frame, but
the default method promotes vectors to data frames, and the data frame
method used to drop them back to vectors.
I've backed the fix out of R-patched.
I am not sure if the current undocumented behaviour on vectors is
100% desirable, but will amend by.default in R-devel to preserve it.
Thomas: I think svymean() needs not to assume that 1-column data frames
will be dropped.
On Mon, 10 Dec 2007, ligges at statistik.uni-dortmund.de wrote:
> by() fails for 1-column matrices and dataframes:
>
> X <- data.frame(a=1:10)
> g <- gl(2,5)
> by(X, g, colMeans)
>
>
> Suggested fix:
>
> --- by-old.R 2007-12-10 15:26:22.501086600 +0100
> +++ by.R 2007-12-10 15:25:58.390477200 +0100
> @@ -26,7 +26,7 @@
> IND[[1]] <- INDICES
> names(IND) <- deparse(substitute(INDICES))[1]
> } else IND <- INDICES
> - FUNx <- function(x) FUN(data[x,], ...)
> + FUNx <- function(x) FUN(data[x, , drop=FALSE], ...)
> nd <- nrow(data)
> ans <- eval(substitute(tapply(1:nd, IND, FUNx)), data)
> attr(ans, "call") <- match.call()
>
>
>
> _
> platform i386-pc-mingw32
> arch i386
> os mingw32
> system i386, mingw32
> status
> major 2
> minor 6.1
> year 2007
> month 11
> day 26
> svn rev 43537
> language R
> version.string R version 2.6.1 (2007-11-26)
>
>
> Uwe Ligges
>
> ______________________________________________
> 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
More information about the R-devel
mailing list