I know there is an easy way to do this ... but I cannot figure it out.
I have a dataframe in my R script that looks something like this:
ABC 1.2 4 8 2.3 4 9 2.3 6 0 1.2 3 3 3.4 2 1 1.2 5 1
Note that A, B, and C are column names. And I'm trying to get variables like this:
sum1 <- [the sum of all B values such that A is 1.2] num1 <- [the number of times A is 1.2]
Any easy way to do this? I basically want to get a data frame that looks like this:
A num totalB 1.2 3 12 etc etc etc
Where "num" is the number of times a certain value of A has appeared, and "totalB" is the sum of the values ββof B, given the value of A.
r aggregate dataframe
Codeguy
source share