ben best <bbest@nceas.ucsb.edu>
2014-04-03 in Santa Barbara, CA USA
dplyr is the next iteration of plyr, focussed on tools for working with data frames.
library(Lahman)
library(plyr)
games <- ddply(Batting, "playerID", summarise, total = sum(G))
head(arrange(games, desc(total)), 5)
playerID total
1 rosepe01 3562
2 yastrca01 3308
3 aaronha01 3298
4 henderi01 3081
5 cobbty01 3035
library(Lahman)
library(dplyr)
Batting %.%
group_by(playerID) %.%
summarise(total = sum(G)) %.%
arrange(desc(total)) %.%
head(5)
Source: local data frame [5 x 2]
playerID total
1 rosepe01 3562
2 yastrca01 3308
3 aaronha01 3298
4 henderi01 3081
5 cobbty01 3035
grammar of data manipulation: sequence of operations on a dataset, rather than setting temporary variables or nesting functions inside one another
readable: minimal quoting needed, operations are easily aligned with another (especially with merge())
fast: written largely in C++, faster than base functions
generic: regardless of backend storage (data.frame, database, Goolge bigquery…)
markdown is a plain text formatting syntax for conversion to HTML (with a tool)
r markdown enables easy authoring of reproducible web reports from R
in rstudio
chunks: text, tables, figures
inline: pi=`r pi` evaluates to “pi=3.1416”
inline
The Arithmetic mean is equal to \( \frac{1}{n} \sum_{i=i}^{n} x_{i} \), or the summation of n numbers divided by n.
The Arithmetic mean is equal to \( \frac{1}{n} \sum_{i=i}^{n} x_{i} \), or the summation of n numbers divided by n.
$$
\frac{1}{n} \sum_{i=i}^{n} x_{i}
$$
\[ \frac{1}{n} \sum_{i=i}^{n} x_{i} \]
post to rpubs from rstudio
post to github
backup: offsite archive (if syncing with remote server)
rewind: roll back changes, so you can experiment and/or clean up code without worry of loss
document: associate changes of code and files with issues and messages
collaborate: with others
publish to web site (github free for public repositories)
sign up at github.com
create or fork a repository, aka “repo”
clone from web to your local desktop
commit changes locally
push changes to your repo
pull request changes from your repo to upstream
| direction | org web | user web | user local |
|---|---|---|---|
github.com/[org]/[repo] |
github.com/[user]/[repo] |
~/github/[repo] |
|
| -> (1x) | -> fork | -> clone | |
| <- | merge {admin} <- | <- pull request | <- push, <-> commit |
where:
[org] is an organization (eg ohi-science)[repo] is a repository in the orgranization (eg ohicore, ohiprep, etc.)[user] is your github usernameRStudio: File > New Project > Version Control
clone
commit and push
book: Reproducible Research with R and RStudio (2013) by Christopher Gandrud http://christophergandrud.github.io/RepResR-RStudio/
markdown: http://www.rstudio.com/ide/docs/authoring/using_markdown
github: https://www.rstudio.com/ide/docs/version_control/overview