[R-gregmisc-users] SF.net SVN: r-gregmisc:[1605] trunk/gdata
Brought to you by:
warnes
From: <wa...@us...> - 2012-09-12 17:39:48
|
Revision: 1605 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1605&view=rev Author: warnes Date: 2012-09-12 17:39:42 +0000 (Wed, 12 Sep 2012) Log Message: ----------- 'stats::aggregate' was made into a generic on 27-Jan-2010, so that attempting to call 'aggregate' on a 'table' object will now incorrectly call 'aggregate.table'. Since 'aggregate.table' can be replaced by a call to tapply using two index vectors, e.g. aggregate.table(x, by1=a, by2=b, mean) can be replaced by tapply(x, INDEX=list(a, b), FUN=mean), the 'aggregate.table' function will now display a warning that it is depreciated and recommending the equivalent call to tapply. It will be removed entirely in a future version of gdata. Modified Paths: -------------- trunk/gdata/R/aggregate.table.R trunk/gdata/man/aggregate.table.Rd Modified: trunk/gdata/R/aggregate.table.R =================================================================== --- trunk/gdata/R/aggregate.table.R 2012-09-12 17:29:38 UTC (rev 1604) +++ trunk/gdata/R/aggregate.table.R 2012-09-12 17:39:42 UTC (rev 1605) @@ -2,14 +2,36 @@ aggregate.table <- function(x, by1, by2, FUN=mean, ... ) { - if(!is.factor(by1)) by1 <- as.factor(by1) - if(!is.factor(by2)) by2 <- as.factor(by2) + warning("'aggregate.table' is depreciated.", + "Please use 'tapply(X=", + deparse(substitute(x)), + ", INDEX=list(", + deparse(substitute(by1)), + ", ", + deparse(substitute(by2)), + "), FUN=", + deparse(substitute(FUN)), + if(length(list(...))>0) + { + l <- list(...) + paste(", ", + paste(names(l),"=", + deparse(substitute(...)), + sep="", + collapse=", ") + ) + }, + ")' instead.") + tapply(X=x, INDEX=list(by1, by2), FUN=FUN, ...) + } - ag <- aggregate(x, by=list(by1,by2), FUN=FUN, ... ) - tab <- matrix( nrow=nlevels(by1), ncol=nlevels(by2) ) - dimnames(tab) <- list(levels(by1),levels(by2)) - - for(i in 1:nrow(ag)) - tab[ as.character(ag[i,1]), as.character(ag[i,2]) ] <- ag[i,3] - tab - } +## aggregate.table <- function(x, by1, by2, FUN=mean, ... ) +## { +## +## tab <- matrix( nrow=nlevels(by1), ncol=nlevels(by2) ) +## dimnames(tab) <- list(levels(by1),levels(by2)) +## +## for(i in 1:nrow(ag)) +## tab[ as.character(ag[i,1]), as.character(ag[i,2]) ] <- ag[i,3] +## tab +## } Modified: trunk/gdata/man/aggregate.table.Rd =================================================================== --- trunk/gdata/man/aggregate.table.Rd 2012-09-12 17:29:38 UTC (rev 1604) +++ trunk/gdata/man/aggregate.table.Rd 2012-09-12 17:39:42 UTC (rev 1605) @@ -53,21 +53,34 @@ \seealso{ \code{\link{aggregate}}, \code{\link{tapply}}, \code{\link{interleave}} } - +\note{This function is DEPRECIATED. Please use \code{tapply} + instead. See example for illustration.} \examples{ # Useful example: # # Create a 2-way table of means, standard errors, and # obs - +set.seed(314159) g1 <- sample(letters[1:5], 1000, replace=TRUE) g2 <- sample(LETTERS[1:3], 1000, replace=TRUE ) dat <- rnorm(1000) stderr <- function(x) sqrt( var(x,na.rm=TRUE) / nobs(x) ) +## Depreciated: means <- aggregate.table( dat, g1, g2, mean ) +## Instead use: +means <- tapply( dat, list(g1, g2), mean ) + +## Depreciated stderrs <- aggregate.table( dat, g1, g2, stderr ) +## Instead use: +stderrs <- tapply( dat, list(g1, g2), stderr ) + +## Depreciated ns <- aggregate.table( dat, g1, g2, nobs ) +## Instead use: +ns <- tapply( dat, list(g1, g2), nobs ) + blanks <- matrix( " ", nrow=5, ncol=3) tab <- interleave( "Mean"=round(means,2), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |