Skip to content
Prev 300768 / 398503 Next

Changing ungrouped cases to grouped cases

Hello,

Still with aggregate, use length() not sum().


dtagroup <- aggregate(y ~ A + B + C, data=dtf, sum)
dtalength <- aggregate(y ~ A + B + C, data=dtf, length)

# Now merge the two
names(dtalength)[4] <- "count"
mm <- merge(dtagroup, dtalength)

# And make it pretty
mm <- mm[, c("y", "A", "B", "C", "count")]
mm

Hope this helps,

Rui Barradas

Em 20-07-2012 19:52, Christopher Desjardins escreveu: