And here is one more approach using the reshape package:
library(reshape)
dataset.d <- melt(dataset, id = 1:2)
cast(dataset.d, gp1 + gp2 ~ variable, mean)
On 9/30/05, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> Check out summaryBy in the doBy package at:
>
> http://genetics.agrsci.dk/~sor
On 9/30/2005 1:41 PM, hadley wickham wrote:
> I'm not entirely sure what you want, but maybe this does the trick?
>
> data.frame.by <- function(data, variables, fun, ...) {
> if (length(variables) == 0 ) {
> df <- data.frame(results = 0)
> df$results <- list(fun(d
On 9/30/2005 1:41 PM, Peter Dalgaard wrote:
> Duncan Murdoch <[EMAIL PROTECTED]> writes:
>
>> I want to calculate a statistic on a number of subgroups of a dataframe,
>> then put the results into a dataframe. (What SAS PROC MEANS does, I
>> think, though it's been years since I used it.)
>>
>>
On Fri, 2005-09-30 at 13:22 -0400, Duncan Murdoch wrote:
> I want to calculate a statistic on a number of subgroups of a dataframe,
> then put the results into a dataframe. (What SAS PROC MEANS does, I
> think, though it's been years since I used it.)
>
> This is possible using by(), but it see
Check out summaryBy in the doBy package at:
http://genetics.agrsci.dk/~sorenh/misc
e.g.
summaryBy(value ~ gp1 + gp2, data = dataset)
On 9/30/05, Duncan Murdoch <[EMAIL PROTECTED]> wrote:
> I want to calculate a statistic on a number of subgroups of a dataframe,
> then put the results in
Duncan Murdoch <[EMAIL PROTECTED]> writes:
> I want to calculate a statistic on a number of subgroups of a dataframe,
> then put the results into a dataframe. (What SAS PROC MEANS does, I
> think, though it's been years since I used it.)
>
> This is possible using by(), but it seems cumbersome
I'm not entirely sure what you want, but maybe this does the trick?
data.frame.by <- function(data, variables, fun, ...) {
if (length(variables) == 0 ) {
df <- data.frame(results = 0)
df$results <- list(fun(data$value, ...))
return(df)