Overview
Teaching: 10 min Exercises: 5 minQuestions
What are the basic
dplyr
functions?How do I implement the basic
dplyr
functions?Objectives
To understand the basic
dplyr
functions:select()
,filter()
,group_by()
, andsummarize()
library(dplyr)
dplyr Challenge
How many countries are in Africa?
A. 5 B. 38 C. 52 D. 142
Answer
C. 52
Code Solution
Africa <- filter(data, continent=="Africa") summarize(Africa, countries = n())
Make a
data.frame
that stores the count of countries per continent?Output Solution
Source: local data frame [5 x 2] continent countries (fctr) (int) 1 Africa 52 2 Americas 25 3 Asia 33 4 Europe 30 5 Oceania 2
Code Solution
data %>% group_by(continent) %>% summarize(countries = n())
Key Points
Use
dplyr
to manipulate, summarize, and analyze your data.