鉴于您的数据是df:
df
library(data.table) dt <- as.data.table(df) dt[, count := .N, by = list(Attribute1, Attribute2)]