Re: [R] mean for subset

2010-01-07 Thread Jerry Floren
Thanks for your insights Matthew. Actually, some of the merged documents are over 1,000 pages. I have never had a programming class, and I had one college statistics course in 1975. I might be in over my head, but R along with Word's mail merge has allowed me to put together some pretty useful rep

Re: [R] mean for subset

2010-01-07 Thread Matthew Dowle
Did you really say you're using Word's mail merge to construct "hundreds" of pages of R code which you then paste in to R ? It sounds like you just missed somehow how to create a function in R. Did you fully read the book Introduction to R ? Did you know R can read xls directly, and connect t

Re: [R] mean for subset

2010-01-07 Thread Jerry Floren
As a novice R user, I face a similar challenge. I am almost afraid to share with this group how I solved it. About 65 labs in our proficiency program submit data on individual Excel spreadsheets with triple replicates. There always are a few labs that do not complete the full set of three replicat

Re: [R] mean for subset

2010-01-06 Thread Matthew Dowle
As can data.table (i.e. do 'having' in one statement) : > DT = data.table(DF) > DT[,list(n=length(NAME),mean(SCORE)),by="NAME"][n==3] NAME n V2 [1,] James 3 64.0 [2,] Tom 3 78.7 > but data.table isn't restricted to SQL functions (such as avg), any R functions can be used,

Re: [R] mean for subset

2010-01-05 Thread Henrique Dallazuanna
Try this: with(split(DF, with(DF, ave(SCORE, NAME, FUN = length)))[['3']], tapply(SCORE, NAME[,drop = TRUE], FUN = mean)) Or: with(DF, tapply(SCORE, NAME, mean))[table(DF$NAME) == 3] On Tue, Jan 5, 2010 at 4:29 PM, Geoffrey Smith wrote: > Hello, does anyone know how to take the mean for a sub

Re: [R] mean for subset

2010-01-05 Thread Gabor Grothendieck
Here is the solution using sqldf which can do it in one statement: > # read in data > Lines <- "OBS NAME SCORE + 1 Tom 92 + 2 Tom 88 + 3 Tom 56 + 4 James85 + 5 James75 + 6 James32 + 7 Dawn 56 + 8

Re: [R] mean for subset

2010-01-05 Thread Achim Zeileis
On Tue, 5 Jan 2010, Geoffrey Smith wrote: Hello, does anyone know how to take the mean for a subset of observations? For example, suppose my data looks like this: OBS NAME SCORE 1 Tom 92 2 Tom 88 3 Tom 56 4 James85 5 James

Re: [R] mean for subset

2010-01-05 Thread Duncan Murdoch
On 05/01/2010 1:29 PM, Geoffrey Smith wrote: Hello, does anyone know how to take the mean for a subset of observations? For example, suppose my data looks like this: OBS NAME SCORE 1 Tom 92 2 Tom 88 3 Tom 56 4 James85 5 Jam

Re: [R] mean for subset

2010-01-05 Thread Gabor Grothendieck
Have a look at this post and the rest of that thread: https://stat.ethz.ch/pipermail/r-help/2010-January/223420.html On Tue, Jan 5, 2010 at 1:29 PM, Geoffrey Smith wrote: > Hello, does anyone know how to take the mean for a subset of observations? > For example, suppose my data looks like this:

[R] mean for subset

2010-01-05 Thread Geoffrey Smith
Hello, does anyone know how to take the mean for a subset of observations? For example, suppose my data looks like this: OBS NAME SCORE 1 Tom 92 2 Tom 88 3 Tom 56 4 James85 5 James75 6 James32 7 Dawn