group on two variables, and then count a string value

Viewed 99

content table

I want to count all the O-V and G in the Kwaleitsbeoordeling column. And I want to group on the Branche and the Status.

df %>% 
group_by(Status) %>% 
Group
  summarize(mean_value = count(Kwaliteitsbeoordeling))

How do I summarise a string value? and group on 2 different columns?

Update:

expected result:

enter image description here

Data update:

Project ID
<dbl>
Branche
<chr>
Status
<chr>
HUB
<chr>
Rayonmanager
<chr>
Kwaliteitsbeoordeling
<chr>
Algemene_indruk
<chr>
Arbo
<chr>
aanvullende_dienstverlening
<chr>
1   Hotels  huidig  Utrecht Janssen O   V   O   V   
2   Overheid    opgezegd    Barendrecht Platter O   O   V   O   
3   Overheid    huidig  Amsterdam   Hartman V   V   G   V   
4   Onderwijs   opgezegd    Amsterdam   Verhoeven   V   O   G   N.V.T   
5   Food    huidig  Amsterdam   Hartman O   O   O   V   
6   Retail  opgezegd    Utrecht Janssen G   O   N.V.T   V   
7   Onderwijs   huidig  Eindhoven   Willems G   V   V   V   
8   Hotels  opgezegd    Barendrecht Velzeboer   G   V   V   G   
9   Food    huidig  Amsterdam   Hartman O   O   G   O   
10  Onderwijs   opgezegd    Barendrecht Platter V   G   O   N.V.T
1 Answers

We can do a group by n() and then reshape to 'wide' format

library(dplyr)
library(tidyr)
df %>%
   group_by(Project_ID, Branche, Kwaliteitsbeoordeling) %>%
   summarise(n = n()) %>%
   pivot_wider(names_from = Kwaliteitsbeoordeling, values_from = n, 
         values_fill = list(n = 0))
Related