I have a table with ID, Category and amount with a few thousand records.
data:
df1 <- data.frame(
ID = c('V1', 'V1', 'V1', 'V3', 'V3', 'V3', 'V4', 'V5','V5','V5'),
Category = c('a', 'a', 'a', 'a', 'b', 'b', 'a', 'b', 'c', 'c'),
Amount = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
Using dplyr I want to group by ID and Category, sum the total amount per group, then filter the results to only have IDs which exist in multiple category.
result:
ID Category Amount_Sum
V3 a 1
V3 b 2
V5 b 1
V5 c 2
I have the following code which groups and sums, but missing how to filter when the ID is in multiple groups
code:
x <- df1 %>%
group_by(ID, Category) %>%
summarize(CNT = n(), amount = sum(Amount)) %>%
filter(????????)