Using dplyr
:
require(dplyr)
df <- data.frame(A = c(1, 1, 2, 3, 3), B = c(2, 3, 3, 5, 6))
df %>% group_by(A) %>% summarise(B = sum(B))
## Source: local data frame [3 x 2]
##
## A B
## 1 1 5
## 2 2 3
## 3 3 11
With sqldf
:
library(sqldf)
sqldf('SELECT A, SUM(B) AS B FROM df GROUP BY A')