This is a simple question but for some reason it is giving me trouble. I have a dataset and there are categories that have multiple data vales. I want to sum these data values so that each category has only one data value. This is a reprex of the columns I want to sum. I've tried lapply but did not obtain the result I wanted
data.frame(category = c("x","x","x","x","x","y","y","y","y","y","z","z","z","z","z"),
value = c(29,-30,48,58,-67,56,-32,75,61,32,-38,24,43,44,-56))
d <- data.frame(
category = c("x","x","x","x","x","y","y","y","y","y","z","z","z","z","z"),
value = c(29,-30,48,58,-67,56,-32,75,61,32,-38,24,43,44,-56))
tapply(d$value, d$category, FUN = sum)
# x y z
# 38 192 17