Re: [R] summary stats on continuous data

2010-06-15 Thread Daniel Malter
You can define a function that does just that: sum the 1s in Acc and divide by the length of Acc. Then use tapply to apply the function for each subject. f=function(x){sum(as.numeric(as.character(x)))/length(x)} tapply(d$Acc,list(d$S),f) HTH, Daniel -- View this message in context: http://r.78

Re: [R] summary stats on continuous data

2010-06-15 Thread Matthew Finkbeiner
Hi Daniel, thanks for your reply. Unfortunately, that is not doing what I need. In the example I sent, there are three subjects (S1, S2 & S3). Each subject has 3 trials worth of data and each trial has 10 samples. What I want to return is the accuracy rate for each subject. The answer is 66.6

Re: [R] summary stats on continuous data

2010-06-15 Thread Daniel Malter
Hi, you should be able to do most of your summaries using tapply() or aggregate(). for your example, tapply(d$Acc,list(d$Sample),table) Here tapply takes Acc, "splits" it by Sample, and then tables Acc (which returns how many 0s/1s were observed in variable Acc for each stratum of Sample). HT

[R] summary stats on continuous data

2010-06-15 Thread Matthew Finkbeiner
I'm sorry for what I'm sure is a terribly simple question. I have a large dataframe along these lines: S<- 1:3 d<- data.frame(cbind(S=rep(paste('S',S,sep=""),each=30), trial=rep(1:3,each=10), FactorA=rep(paste('L',1,sep=""),each=30), Acc= c(rep(1,each=20),rep(0,each=10)), Sample=rep(1:10,