Dear R-Users, I have a big data set "mydata" with repeated observation and some missing values. It looks like the format below:
userid sex item score1 score2 1 0 1 1 1 1 0 2 0 1 1 0 3 NA 1 1 0 4 1 0 2 1 1 0 1 2 1 2 NA 1 2 1 3 1 NA 2 1 4 NA 0 3 0 1 1 0 3 0 2 1 NA 3 0 3 1 0 3 0 4 0 0 I wound like to summarise the dataset such that i get something in the format of userid sumscore1 countscore1 meanscore1 sumscore2 countscore2 meanscore2 1 2 3 0.67 3 4 0.75 2 1 2 0.5 2 3 0.67 3 3 4 0.75 0 3 0.00 I tried using : means <- data.frame(aggregate(mydata[, 4:5],by=list(mydata$userid),FUN="mean", na.rm="TRUE")) and sums <- data.frame(aggregate(mydata[, 4:5],by=list(mydata$userid),FUN="sum", na.rm="TRUE")) so that i could merge the two data.frames later. This works quite okay but i still can not get a function that can give me a data.frame for the counts!! Something like this:: counts <- data.frame(aggregate(mydata[, 4:5],by=list(mydata$userid),FUN="count", na.rm="TRUE")). Any advice? Trevor Belgium -- View this message in context: http://n4.nabble.com/score-counts-in-an-aggregate-function-tp2007152p2007152.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.