## - Always plural
## - Package name in quotes
## - Capitalization matters
install.packages("dplyr")
## - Always singular
## - Quotes not needed
## - Capitalization matters
library(dplyr)
## Init ========================================================================
library(dplyr)
data(cars)
## Are these two lines of code equivalent? =====================================
cars[cars$speed > 20,]
filter(cars, speed > 20)
Answer on next slide
Because otherwise I was going to look silly.
speed dist
1 22 66
2 23 54
3 24 70
4 24 92
5 24 93
6 24 120
7 25 85
Not enough room for Captain Smith, but run this code too.
## Easy, but limited
colMeans(cars)
speed dist
15.40 42.98
## More complex, more powerful
cars %>%
summarize(n_rows = n(),
speed = mean(speed),
dist = mean(dist)
)
+ + + +
n_rows speed dist
1 50 15.4 42.98
Titanic in Cobh Harbour, County Cork Ireland