Dear r-list,
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

-- 
Nice&Lovely

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to