-4

I have a data frame with 4 columns. I want to produce a new data frame which groups by the first three columns, and provides a count of the instances of "Yes" in the fourth column

So

enter image description here

becomes

enter image description here

How do I do this in R

Thanks for your help

nir020
  • 97
  • 1
  • 1
  • 5
  • 5
    Hi nir020. Please do not post images of code or data (as specified in this forums guidelines). If you add a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) you could make it easier for others to find and test an answer to your question. That way you can help others to help you! – dario Feb 09 '21 at 15:14
  • 4
    what do you mean @dario, it is inperfect .NORM format.. pleze update your system to read ;-) https://xkcd.com/2116/ – Wimpel Feb 09 '21 at 15:16
  • @Wimpel you desearve +10 points for sharing this link! LOL – Terru_theTerror Feb 09 '21 at 15:19

2 Answers2

0

It would be best if I had a set of your actual data to verify this works and returns the output you desire, but the following should work.

library(dplyr)
df %>% 
  group_by(across(1:4)) %>%
  summarize(Count = sum(`Passed Test` == "Y"))
Ben Norris
  • 5,639
  • 2
  • 6
  • 15
0

An option with base R

aggregate(`Passed Test` ~ ., df, FUN = function(x) sum(x == "Y"))
akrun
  • 874,273
  • 37
  • 540
  • 662