Skip to content

Aggregating by a grouping

1 message · Richard Cotton

#
Try this:

testdf <- data.frame(book=factor(c("A", "B", "C", "D", "A", "C", "D", 
"B")),  value=c(10,11,9,8,12,4,5,7))
bookgroup <- rep("A1", nrow(testdf))
bookgroup[testdf$book=="C" | testdf$book=="D"] <- "A2"
tapply(testdf$value, bookgroup, sum)

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}