I know there is an easy way to do this...but, I can\'t figure it out.
I have a dataframe in my R script that looks something like this:
A B C 1.2
Here is a solution using data.table for memory and time efficiency
data.table
library(data.table) DT <- as.data.table(df) DT[, list(totalB = sum(B), num = .N), by = A]
To subset only rows where C==1 (as per the comment to @aix answer)
C==1
DT[C==1, list(totalB = sum(B), num = .N), by = A]