[R] Counting within groups / means by groups
Jeff Newmiller
jdnewmil at dcn.davis.CA.us
Mon Nov 10 16:19:27 CET 2014
Help file ?ave should apply here.
Please read the Posting Guide mentioned in the footer of every email on this list and on the list manager page for this mailing list. It warns you to read the archives before posting and to post in plain text format rather than HTML format.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
On November 10, 2014 6:39:47 AM PST, David Studer <studerov at gmail.com> wrote:
>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 at 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.
More information about the R-help
mailing list