Summarizing data with dplyr

The following makes use of the dplyr package. You may need to install it from CRAN using the code install.packages("dplyr") if you want to run this on your computer. (The package is already installed on the notebook container, however.)


Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

Here we use data from the British Election Study 2010. The data set bes2010feelings.RData is prepared from the original available at by removing identifying information and scrambling the data.


# A convenience function
Mean <- function(x,...) mean(x,na.rm=TRUE,...)

bes2010feelings %>% group_by(wave,region) %>%
`summarise()` regrouping output by 'wave' (override with `.groups` argument)

  wave region   Brown    Cameron  Clegg    N
1 Pre  England  4.092674 5.284810 4.618690 1159
2 Pre  Scotland 5.395000 4.502591 4.405229  207
3 Pre  Wales    4.328244 4.774194 4.592233  132
4 Pre  NA       4.507143 4.929870 4.426573  437
5 Post England  4.140990 5.441454 5.160313 2175
6 Post Scotland 5.510769 4.539075 4.513793  665
7 Post Wales    4.307692 4.855895 4.814480  235

Downloadable R script and interactive version


The link with the “jupyterhub” icon directs you to an interactive Jupyter1 notebook, which runs inside a Docker container2. There are two variants of the interative notebook. One shuts down after 60 seconds and does not require a sign it. The other requires sign in using your ORCID3 credentials, yet shuts down only after 24 hours. (There is no guarantee that such a container persists that long, it may be shut down earlier for maintenance purposes.) After shutdown all data within the container will be reset, i.e. all files created by the user will be deleted.4

Above you see a rendered version of the Jupyter notebook.5


For more information about Jupyter see The Jupyter notebooks make use of the IRKernel package.


For more information about Docker see The container images were created with repo2docker, while containers are run with docker spawner.


ORCID is a free service for the authentication of researchers. It also allows to showcase publications and contributions to the academic community such as peer review.. See for more information.


The Jupyter notebooks come with NO WARRANTY whatsoever. They are provided for educational and illustrative purposes only. Do not use them for production work.


The notebook is rendered with the help of the nbsphinx extension.