Interactive pivot tables with R

[This article was first published on mages' blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I love interactive pivot tables. That is the number one reason why I keep using spreadsheet software. The ability to look at data quickly in lots of different ways, without a single line of code helps me to get an understanding of the data really fast.

Perhaps I can do the same now in R as well. At yesterday’s LondonR meeting Enzo Martoglio presented briefly his rpivotTable package. Enzo builds on Nicolas Krutchen’s PivotTable.js JavaScript library that provides drag’n’drop functionality and wraps it with htmlwidget into R. The result is an interactive pivot table rendered in either your default browser or the viewer pane of RStudio with one line of code:

## Install packages<br />library(devtools)<br />install_github("ramnathv/htmlwidgets") <br />install_github("smartinsightsfromdata/rpivotTable")<br />## Load rpivotTable<br />library(rpivotTable)<br />data(mtcars)<br />## One line to create pivot table<br />rpivotTable(mtcars, rows="gear", col="cyl", aggregatorName="Average", <br />vals="mpg", rendererName="Treemap")

The following animated Gif from Nicolas’ project page gives an idea of the interactive functionality of PivotTable.js.

Example of PivotTable.js Source: Nicolas Kruchten

Session Info

R version 3.1.3 (2015-03-09)<br />Platform: x86_64-apple-darwin13.4.0 (64-bit)<br />Running under: OS X 10.10.2 (Yosemite)<br /><br />locale:<br />[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8<br /><br />attached base packages:<br />[1] stats     graphics  grDevices utils    <br />[5] datasets  methods   base     <br /><br />other attached packages:<br />[1] rpivotTable_0.1.3.4<br /><br />loaded via a namespace (and not attached):<br />[1] digest_0.6.8      htmltools_0.2.6  <br />[3] htmlwidgets_0.3.2 RJSONIO_1.3-0    <br />[5] tools_3.1.3       yaml_2.1.13

To leave a comment for the author, please follow the link and comment on their blog: mages' blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)