Re: [R] best way to aggregate / rearrange data.frame with different data types

2011-07-11 Thread Dennis Murphy
Hi: Here's another approach using the plyr and reshape packages. (There are multiple ways to do this, BTW.) ## (1) library(plyr) > ddply(dat, .(Subject, gender, comment), summarise, mean_y = mean(y)) Subject gender comment mean_y 1 1 w comment A 3.881864 2 2 m comment

Re: [R] best way to aggregate / rearrange data.frame with different data types

2011-07-11 Thread David Winsemius
On Jul 11, 2011, at 11:55 AM, Martin Batholdy wrote: Hi, I have a data.frame that looks like this: Subject <- c(rep(1,4), rep(2,4), rep(3,4)) y <- rnorm(12, 3, 2) gender <- c(rep("w",4), rep("m",4), rep("w",4)) comment <- c(rep("comment A",4), rep("comment B",4), rep("comment C", 4)) dat

[R] best way to aggregate / rearrange data.frame with different data types

2011-07-11 Thread Martin Batholdy
Hi, I have a data.frame that looks like this: Subject <- c(rep(1,4), rep(2,4), rep(3,4)) y <- rnorm(12, 3, 2) gender <- c(rep("w",4), rep("m",4), rep("w",4)) comment <- c(rep("comment A",4), rep("comment B",4), rep("comment C",4)) data <- data.frame(Subject,y,gender,comment) data Subject