79275878

Date: 2024-12-12 16:38:12
Score: 0.5
Natty:
Report link

This will do the trick

library(dplyr)

test <- data.table::data.table(name = c(rep(1,20), rep(2,20), rep(3,20)), type = c(rep("apple",10), rep("pear",10), rep("apple",15), rep("pear",5), rep("pear",20)))

test %>%
  group_by(name) %>%
  summarise(diff = sum(type == "apple") - sum(type == "pear"))
Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: thekangaroofactory