Reputation: 57
I have a dataframe that looks like this:
And I want to get this, that is, a single row per Group, with a column for the % of As in all the ID_1_Subgroup for each Group, together with the sum of ValueSubgroup, for each group too):
Can someone help? I have seen other issues (like this: Summarizing by group and subgroup) which are similar but not for R.
Upvotes: 0
Views: 32
Reputation: 887088
We can do
library(dplyr)
df1 %>%
group_by(Group) %>%
summarise(PercA = mean(id_1_Subgroup == "A"),
SumOfValueSubgroup = sum(ValueSubgroup))
Upvotes: 1