d <- data.frame(
group = c("a", "a", "b"),
stringsAsFactors = FALSE)
dl <- lapply(
split(d, d$group),
function(di) {
data.frame(
# note: di$group is a possibly length>1 vector!
# pseudo aggregate it to the value that is
# constant for each group, confirming it is constant.
group_label = psagg(di$group),
group_count = nrow(di),
stringsAsFactors = FALSE
)
})
do.call(rbind, dl)
Run the code above in your browser using DataLab