On May 5, 2010, at 5:32 PM, utkarshsinghal wrote:
Extending my question further, I want to apply different FUN
arguments on three fields and the "by" argument also contains more
than one field.
For example:
set.seed(100)
d = data.frame(a=sample(letters[1:2],
20
,replace
=
T
),b
=
sam
Try this:
do.call("rbind", by(d, d[1:2], function(x) with(x, data.frame(x[1,
1:2], `mean c` = mean(c), `sum d` = sum(d), `has X` = "X" %in% e,
check.names = FALSE
or this (which uses 1 or 0 to mean TRUE or FALSE in the last column):
> library(sqldf) # see http://sqldf.googlecode.com
> sqldf
Extending my question further, I want to apply different FUN arguments
on three fields and the "by" argument also contains more than one field.
For example:
set.seed(100)
d =
data.frame(a=sample(letters[1:2],20,replace=T),b=sample(3,20,replace=T),c=rpois(20,1),d=rbinom(20,1,0.5),e=rep(c("X","Y")
Try this:
> library(doBy)
> summaryBy(breaks ~ ., warpbreaks, FUN = c(mean, sum, length))
wool tension breaks.mean breaks.sum breaks.length
1A L44.6401 9
2A M24.0216 9
3A H24.6221 9
On 11/23/2009 07:15 PM, utkarshsinghal wrote:
Hi All,
I am currently doing the following to compute summary statistics of
aggregated data:
a = aggregate(warpbreaks$breaks, warpbreaks[,-1], mean)
b = aggregate(warpbreaks$breaks, warpbreaks[,-1], sum)
c = aggregate(warpbreaks$breaks, warpbreaks[
Hi All,
I am currently doing the following to compute summary statistics of
aggregated data:
a = aggregate(warpbreaks$breaks, warpbreaks[,-1], mean)
b = aggregate(warpbreaks$breaks, warpbreaks[,-1], sum)
c = aggregate(warpbreaks$breaks, warpbreaks[,-1], length)
ans = cbind(a, b[,3], c[,3])
Thi
6 matches
Mail list logo