Overview
Teaching: 10 min Exercises: 5 minQuestions
What are the basic
dplyrfunctions?How do I implement the basic
dplyrfunctions?Objectives
To understand the basic
dplyrfunctions: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.framethat 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 2Code Solution
data %>% group_by(continent) %>% summarize(countries = n())
Key Points
Use
dplyrto manipulate, summarize, and analyze your data.