> Hi All, > > Sorry for what I imagine is quite a basic question. I have been trying to do is create latency averages for each state (1-8) for each participant (n=13) in each condition (1-10). I'm not sure what function I would need, or what the most efficient ay of calculating this would be. If you have any help with that I would be very grateful. > > structure(list(subject = c(1L, 1L, 1L, 1L, 1L, 1L), conditionNo = c(1L, > 1L, 1L, 1L, 1L, 1L), state = c(5L, 8L, 7L, 8L, 1L, 7L), latency = c(869L, > 864L, 1004L, 801L, 611L, 679L)), .Names = c("subject", "conditionNo", > "state", "latency"), row.names = 3:8, class = "data.frame") > > Thanks again, > > Laura
I would suggest using summaryBy() library(doBy) # sample data with you specifications subject <- as.factor(rep(seq(13), each = 5)) state <- as.factor(sample(c(1:8), 65, replace = TRUE)) condition <- as.factor(sample(c(1:10), 65, replace = TRUE)) latency <- runif(65, min=750, max = 1100) dat <- data.frame(subject, state, condition, latency) summaryBy(latency~subject+state+condition, data = dat, FUN = function(x) mean(x)) Regards, On Mon, Dec 23, 2013 at 6:31 AM, Laura Bethan Thomas [lbt1] <lbt1@aber.ac.uk> wrote:> > Hi All, > > > > Sorry for what I imagine is quite a basic question. I have been trying > to do is create latency averages for each state (1-8) for each participant > (n=13) in each condition (1-10). I'm not sure what function I would need, > or what the most efficient ay of calculating this would be. If you have any > help with that I would be very grateful. > > > > structure(list(subject = c(1L, 1L, 1L, 1L, 1L, 1L), conditionNo = c(1L, > > 1L, 1L, 1L, 1L, 1L), state = c(5L, 8L, 7L, 8L, 1L, 7L), latency = c(869L, > > 864L, 1004L, 801L, 611L, 679L)), .Names = c("subject", "conditionNo", > > "state", "latency"), row.names = 3:8, class = "data.frame") > > > > Thanks again, > > > > Laura > > ______________________________________________ > R-help@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. >-- Charles Determan Integrated Biosciences PhD Candidate University of Minnesota [[alternative HTML version deleted]]
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:> Hi All, > > Sorry for what I imagine is quite a basic question. I have been trying to do is create latency averages for each state (1-8) for each participant (n=13) in each condition (1-10). I'm not sure what function I would need, or what the most efficient ay of calculating this would be. If you have any help with that I would be very grateful. > > structure(list(subject = c(1L, 1L, 1L, 1L, 1L, 1L), conditionNo = c(1L, > 1L, 1L, 1L, 1L, 1L), state = c(5L, 8L, 7L, 8L, 1L, 7L), latency = c(869L, > 864L, 1004L, 801L, 611L, 679L)), .Names = c("subject", "conditionNo", > "state", "latency"), row.names = 3:8, class = "data.frame") > > Thanks again, > > Laura______________________________________________ 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 All, >> >> Sorry for what I imagine is quite a basic question. I have been trying to do is create latency averages for each state (1-8) for each participant (n=13) in each condition (1-10). I'm not sure what function I would need, or what the most efficient ay of calculating this would be. If you have any help with that I would be very grateful. >> >> structure(list(subject = c(1L, 1L, 1L, 1L, 1L, 1L), conditionNo = c(1L, >> 1L, 1L, 1L, 1L, 1L), state = c(5L, 8L, 7L, 8L, 1L, 7L), latency = c(869L, >> 864L, 1004L, 801L, 611L, 679L)), .Names = c("subject", "conditionNo", >> "state", "latency"), row.names = 3:8, class = "data.frame") >>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