Neat way of using R for pivoting?
On 9/20/05, Greg Snow <greg.snow at ihc.com> wrote:
"BANNISTER, Keith" <keith.bannister at astrium.eads.net> 09/20/05
09:46AM >>>
Hi, I'd like to use R to do what excel pivot tables do, and plot
results. R does not have pivot tables and I hope that it never does. My experiance with pivot tables is that they encourage poor initial design followed by non-easily-reproducable post-hoc twiddling. R encourages proper initial design followed by fixing the core design in cases where things don't turn out the way you intended. In R I prefer to work with script files and save the file. If the table or graph does not turn out the way I intended, then I just edit the script file and rerun it. While this may be a little more work than clicking on a pivot table at first, in the long run I find it saves more time. Consider the situation where you create a table/graph, then a month later your boss/client/coworker finds some typos in the original data and needs the table and/or graph recreated with the corrected data (or maybe a new dataset that needs a similar graph/table). With the pivot table you need to try and remember everything that you clicked on and click on it again. With the R script file you just fix the data (or load in the new data) and rerun the script and your done. OK, enough of my ranting, on to helping with your problem.
Just one comment here lest we be arguing against a strawman. While I agree that reproducibility can be a problem with pivot tables if created interactively and this applies to just about anything you do in Excel if done interactively, it should also be realized that Excel is completely programmable, like R, using VBA or any language (including R!) via its COM object interface. The fact that Excel has both an interactive interface and a script-based interface whereas R has only a script-based interface puts it ahead, not behind, R in at least some respects.