Message-ID: <13E9A67E-9E36-4599-882F-1605518482E1@comcast.net>
Date: 2010-01-04T03:58:31Z
From: David Winsemius
Subject: function in aggregate applied to specific columns only
In-Reply-To: <5E722D67-76E1-49A7-AE5B-590090A37CD2@acad.umass.edu>
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)
> basicSubMean <- aggregate(basicSub, by=list(basicSub$student),
> FUN=mean, na.rm=TRUE)
> basicSubMean <- aggregate(basicSub$score, by=list(basicSub
$student), FUN=mean, na.rm=TRUE)
> basicSubMean
Group.1 x
1 1 55.0
2 2 60.0
3 3 67.5
>
> This doesn't work, one cannot take the mean of a factor (gender).
> Is there any way of specifying which columns to use for the mean? I
> want to aggregate by student, obtaining mean scores, and assume any
> other factors are unchanging in a specific student, ie. gender.
>
> Thanks
> [[alternative HTML version deleted]]
--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT