Skip to content
Prev 246892 / 398506 Next

YourCast Data Format

Thomas Jensen-6 wrote:
The base R-method uses "by" followed by "do.call":

dt = your data structure in the mail which has only one country, so the
result is a bit confusing

dt.by = by(dt,dt$Country, function(x){
  # put you own calculation here
  data.frame(Absention.neg=mean(x$Abstention.Neg),
             Absention.neg=mean(x$Abstention.Neg))
})

do.call("rbind",dt.by)

This sequence is not really intuitive, so an add-on industry has evolved,
for examples in packages doBy (fast, straightforward) and plyr (can be slow,
but comprehensive and consistent). Best is you try the base method first,
and work with the packages later.

Dieter