Hi everyone! I have problems finding a solution to the following two problems:
My sample-dataframe consists of two variables "group" and "value": group<-c("A", "A", "A", "B", "B", "B", "B", "C") value<-c(1,3,2,2,2,4,4,1) df<-as.data.frame(cbind(group, value)) Problem 1: ********** Now I'd like to count the number of group-A-cases, group-B-cases etc and write this number into a new column. It should be like: count_group<-c(3, 3, 3, 4, 4, 4, 4, 1) Problem 2: *********** I'd like to add new column with the mean values (or any other function) within my groups. E.g: Group A: (1+3+2)/3=2 Group B: (2+2+4+4)/4=3 Group C: =1 Now I'd add another column 2 2 3 3 3 3 1 Can anyone help me, how this can be done best? Thank you! David [[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.