> That makes eight solutions. Any others? :)
A ninth was detailed in two other threads last month. The first link
compares to ave().
http://tolstoy.newcastle.edu.au/R/e8/help/09/12/9014.html
http://tolstoy.newcastle.edu.au/R/e8/help/09/12/8830.html
"Dennis Murphy" wrote in message
news:9a8a6c6
Just for the fun of it, here are two more: by and ave.
> with(basicSub, by(score, student, mean))
student: 1
[1] 55
student: 2
[1] 60
student: 3
[1] 67.5
Not my favorite prin
Here are 6 ways:
1. aggregate
> aggregate(basicSub["score"], basicSub["student"], mean)
student score
1 1 55.0
2 2 60.0
3 3 67.5
2. tapply
> with(basicSub, tapply(score, student, mean))
123
55.0 60.0 67.5
3. summaryBy in doBy package
> library(doBy)
> summary
You want this?
> basicSubMean <- aggregate(basicSub[c("score")], by=list(basicSub$student),
FUN=mean, na.rm=TRUE)
> basicSubMean
Group.1 score
1 1 55.0
2 2 60.0
3 3 67.5
bests
milton
On Sun, Jan 3, 2010 at 10:46 PM, david hilton shanabrook <
dhsha...@acad.umass.edu> wrote:
Hi:
Perhaps the plyr package would be useful. It contains functions colwise(),
numcolwise() and
catcolwise() that will perform the same operation on the stated type of
object. In this case,
numcolwise() is appropriate:
> str(basicSub)
'data.frame': 5 obs. of 3 variables:
$ student: num 1 2 3
On Jan 3, 2010, at 10:46 PM, david hilton shanabrook wrote:
I want to use aggregate with the mean function on specific columns
gender <- factor(c("m", "m", "f", "f", "m"))
student <- c(0001, 0002, 0003, 0003, 0001)
score <- c(50, 60, 70, 65, 60)
basicSub <- data.frame(student, gender, score)
b
I want to use aggregate with the mean function on specific columns
gender <- factor(c("m", "m", "f", "f", "m"))
student <- c(0001, 0002, 0003, 0003, 0001)
score <- c(50, 60, 70, 65, 60)
basicSub <- data.frame(student, gender, score)
basicSubMean <- aggregate(basicSub, by=list(basicSub$student), FU
7 matches
Mail list logo