Displaying 1 result from an estimated 1 matches for "handleonegroup".
2005 Sep 30
4
by() processing on a dataframe
...- data.frame(gp1 = rep(1:2, c(4,4)), gp2 = rep(1:4,
c(2,2,2,2)), value = rnorm(8))
> dataset
gp1 gp2 value
1 1 1 0.9493232
2 1 1 -0.0474712
3 1 2 -0.6808021
4 1 2 1.9894999
5 2 3 2.0154786
6 2 3 0.4333056
7 2 4 -0.4746228
8 2 4 0.6017522
>
> handleonegroup <- function(subset) data.frame(gp1 = subset$gp1[1],
+ gp2 = subset$gp2[1], statistic = mean(subset$value))
>
> bylist <- by(dataset, list(dataset$gp1, dataset$gp2), handleonegroup)
>
> result <- do.call('rbind', bylist)
> result
gp1 gp2 statistic
1 1 1...