Skip to content

Calculating group means

5 messages · Laura Thomas, Charles Determan Jr, arun +2 more

#
#
Hi,
You could either try:
#dat1 ##dataset
aggregate(latency~.,data=dat1,mean)

#or
?library(data.table)
?dt1 <- data.table(dat1,key=c('subject','conditionNo','state'))
?dt1[,mean(latency),by=c('subject','conditionNo','state')]

A.K.
On Monday, December 23, 2013 2:20 PM, Laura Bethan Thomas [lbt1] <lbt1 at aber.ac.uk> wrote:
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
#
On 12/23/2013 11:31 PM, Laura Bethan Thomas [lbt1] wrote:
Hi Laura,
You can do it like this:

# make up enough data to do the calculation
lbtdat<-data.frame(subject=rep(1:13,each=160),
  condition=rep(rep(rep(1:10,each=8),2),13),
  state=rep(rep(1:8,20),13),
  latency=sample(600:1100,2080,TRUE))
by(lbtdat$latency,list(lbtdat$subject,
  lbtdat$condition,lbtdat$state),mean)

but you are going to get a rather long list of means.

Jim
#
Jim:

Did you forget about with() ?

Instead of:

 by(lbtdat$latency,list(lbtdat$subject,
  lbtdat$condition,lbtdat$state),mean)

##do

with(ibtdat,by(latency,list(subject,condition,state),mean))


Bert Gunter

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
H. Gilbert Welch
On Mon, Dec 23, 2013 at 6:37 PM, Jim Lemon <jim at bitwrit.com.au> wrote: