class: center middle section-title section-title-2 # Transform data<br>with dplyr .class-info[ <figure> <img src="img/02c/dplyr.png" alt="dplyr" title="dplyr" width="15%"> </figure> ] --- class: title title-2 # The tidyverse <figure> <img src="img/02c/tidyverse-language.png" alt="tidyverse and language" title="tidyverse and language" width="100%"> </figure> ??? From "Master the Tidyverse" by RStudio --- class: title title-2 # The tidyverse .center[ <figure> <img src="img/02c/tidyverse.png" alt="The tidyverse" title="The tidyverse" width="50%"> </figure> ] --- class: title title-2 # dplyr: verbs for manipulating data <table> <tr> <td>Extract rows with <code>filter()</code></td> <td><img src="img/02c/filter.png" alt="filter" title="filter" height="80px"></td> </tr> <tr> <td>Extract columns with <code>select()</code></td> <td><img src="img/02c/select.png" alt="select" title="select" height="80px"></td> </tr> <tr> <td>Arrange/sort rows with <code>arrange()</code></td> <td><img src="img/02c/arrange.png" alt="arrange" title="arrange" height="80px"></td> </tr> <tr> <td>Make new columns with <code>mutate()</code></td> <td><img src="img/02c/mutate.png" alt="mutate" title="mutate" height="80px"></td> </tr> <tr> <td>Make group summaries with<br><code>group_by() %>% summarize()</code></td> <td><img src="img/02c/summarize.png" alt="summarize" title="summarize" height="80px"></td> </tr> </table> --- layout: false class: title title-2 # `filter()` .box-inv-2[Extract rows that meet some sort of test] .pull-left[ <code class ='r hljs remark-code'>filter(<b><span style="background-color:#FFDFD1">DATA</span></b>, <b><span style="background-color:#FFD0CF">...</span></b>)</code> ] .pull-right[ - <b><span style="background: #FFDFD1">`DATA`</span></b> = Data frame to transform - <b><span style="background: #FFD0CF">`...`</span></b> = One or more tests <br>.small[`filter()` returns each row for which the test is TRUE] ] --- <code class ='r hljs remark-code'>filter(<b><span style="background-color:#FFDFD1">gapminder</span></b>, <b><span style="background-color:#FFD0CF">country == "Denmark"</span></b>)</code> .pull-left[ <table> <thead> <tr> <th style="text-align:left;"> country </th> <th style="text-align:left;"> continent </th> <th style="text-align:left;"> year </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> Asia </td> <td style="text-align:left;"> 1952 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> Asia </td> <td style="text-align:left;"> 1957 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> Asia </td> <td style="text-align:left;"> 1962 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> Asia </td> <td style="text-align:left;"> 1967 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> Asia </td> <td style="text-align:left;"> 1972 </td> </tr> <tr> <td style="text-align:left;"> … </td> <td style="text-align:left;"> … </td> <td style="text-align:left;"> … </td> </tr> </tbody> </table> ] -- .pull-right[ <table> <thead> <tr> <th style="text-align:left;"> country </th> <th style="text-align:left;"> continent </th> <th style="text-align:right;"> year </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Denmark </td> <td style="text-align:left;"> Europe </td> <td style="text-align:right;"> 1952 </td> </tr> <tr> <td style="text-align:left;"> Denmark </td> <td style="text-align:left;"> Europe </td> <td style="text-align:right;"> 1957 </td> </tr> <tr> <td style="text-align:left;"> Denmark </td> <td style="text-align:left;"> Europe </td> <td style="text-align:right;"> 1962 </td> </tr> <tr> <td style="text-align:left;"> Denmark </td> <td style="text-align:left;"> Europe </td> <td style="text-align:right;"> 1967 </td> </tr> <tr> <td style="text-align:left;"> Denmark </td> <td style="text-align:left;"> Europe </td> <td style="text-align:right;"> 1972 </td> </tr> <tr> <td style="text-align:left;"> Denmark </td> <td style="text-align:left;"> Europe </td> <td style="text-align:right;"> 1977 </td> </tr> </tbody> </table> ] --- class: title title-2 # Logical tests <table> <tr> <th class="cell-center">Test</th> <th class="cell-left">Meaning</th> <th class="cell-center">Test</th> <th class="cell-left">Meaning</th> </tr> <tr> <td class="cell-center"><code class="remark-inline-code">x < y</code></td> <td class="cell-left">Less than</td> <td class="cell-center"><code class="remark-inline-code">x %in% y</code></td> <td class="cell-left">In (group membership)</td> </tr> <tr> <td class="cell-center"><code class="remark-inline-code">x > y</code></td> <td class="cell-left">Greater than</td> <td class="cell-center"><code class="remark-inline-code">is.na(x)</code></td> <td class="cell-left">Is missing</td> </tr> <tr> <td class="cell-center"><code class="remark-inline-code">==</code></td> <td class="cell-left">Equal to</td> <td class="cell-center"><code class="remark-inline-code">!is.na(x)</code></td> <td class="cell-left">Is not missing</td> </tr> <tr> <td class="cell-center"><code class="remark-inline-code">x <= y</code></td> <td class="cell-left">Less than or equal to</td> </tr> <tr> <td class="cell-center"><code class="remark-inline-code">x >= y</code></td> <td class="cell-left">Greater than or equal to</td> </tr> <tr> <td class="cell-center"><code class="remark-inline-code">x != y</code></td> <td class="cell-left">Not equal to</td> </tr> </table> --- class: title title-2 section-title-inv-2 # Your turn #1: Filtering .box-2[Use `filter()` and logical tests to show…] 1. The data for Canada 2. All data for countries in Oceania 3. Rows where the life expectancy is greater than 82
03
:
00
--- .medium[ ```r filter(gapminder, country == "Canada") ``` ] -- .medium[ ```r filter(gapminder, continent == "Oceania") ``` ] -- .medium[ ```r filter(gapminder, lifeExp > 82) ``` ] --- class: title title-2 # `filter()` with multiple conditions .box-inv-2[Extract rows that meet *every* test] <code class ='r hljs remark-code'>filter(<b><span style="background-color:#FFDFD1">gapminder</span></b>, <b><span style="background-color:#FFD0CF">country == "Denmark", year > 2000</span></b>)</code> --- <code class ='r hljs remark-code'>filter(<b><span style="background-color:#FFDFD1">gapminder</span></b>, <b><span style="background-color:#FFD0CF">country == "Denmark", year > 2000</span></b>)</code> .pull-left[ <table> <thead> <tr> <th style="text-align:left;"> country </th> <th style="text-align:left;"> continent </th> <th style="text-align:left;"> year </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> Asia </td> <td style="text-align:left;"> 1952 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> Asia </td> <td style="text-align:left;"> 1957 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> Asia </td> <td style="text-align:left;"> 1962 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> Asia </td> <td style="text-align:left;"> 1967 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> Asia </td> <td style="text-align:left;"> 1972 </td> </tr> <tr> <td style="text-align:left;"> … </td> <td style="text-align:left;"> … </td> <td style="text-align:left;"> … </td> </tr> </tbody> </table> ] -- .pull-right[ <table> <thead> <tr> <th style="text-align:left;"> country </th> <th style="text-align:left;"> continent </th> <th style="text-align:right;"> year </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Denmark </td> <td style="text-align:left;"> Europe </td> <td style="text-align:right;"> 2002 </td> </tr> <tr> <td style="text-align:left;"> Denmark </td> <td style="text-align:left;"> Europe </td> <td style="text-align:right;"> 2007 </td> </tr> </tbody> </table> ] --- class: title title-2 # Boolean operators <table> <tr> <th class="cell-center">Operator</th> <th class="cell-center">Meaning</th> </tr> <tr> <td class="cell-center"><code class="remark-inline-code">a & b</code></td> <td class="cell-center">and</td> </tr> <tr> <td class="cell-center"><code class="remark-inline-code">a | b</code></td> <td class="cell-center">or</td> </tr> <tr> <td class="cell-center"><code class="remark-inline-code">!a</code></td> <td class="cell-center">not</td> </tr> </table> --- class: title title-2 # Default is "and" .box-inv-2[These do the same thing:] <code class ='r hljs remark-code'>filter(<b><span style="background-color:#FFDFD1">gapminder</span></b>, <b><span style="background-color:#FFD0CF">country == "Denmark", year > 2000</span></b>)</code> <code class ='r hljs remark-code'>filter(<b><span style="background-color:#FFDFD1">gapminder</span></b>, <b><span style="background-color:#FFD0CF">country == "Denmark" & year > 2000</span></b>)</code> --- class: title title-2 section-title-inv-2 # Your turn #2: Filtering .box-2[Use `filter()` and Boolean logical tests to show…] 1. Canada before 1970 2. Countries where life expectancy in 2007 is below 50 3. Countries where life expectancy in 2007 is below 50 and are not in Africa
03
:
00
--- ```r filter(gapminder, country == "Canada", year < 1970) ``` -- ```r filter(gapminder, year == 2007, lifeExp < 50) ``` -- ```r filter(gapminder, year == 2007, lifeExp < 50, continent != "Africa") ``` --- class: title title-2 # Common mistakes .pull-left[ .box-inv-2[Collapsing multiple tests<br>into one] .small-code[ <code class ='r hljs remark-code'>filter(gapminder, <b><span style="color:#FF4136">1960 < year < 1980</span></b>)</code> ] .small-code[ <code class ='r hljs remark-code'>filter(gapminder, <br> <b><span style="color:#2ECC40">year > 1960, year < 1980</span></b>)</code> ] ] -- .pull-right[ .box-inv-2[Using multiple tests<br>instead of `%in%`] .small-code[ <code class ='r hljs remark-code'>filter(gapminder, <br> <b><span style="color:#FF4136">country == "Mexico", <br> country == "Canada", <br> country == "United States"</span></b>)</code> ] .small-code[ <code class ='r hljs remark-code'>filter(gapminder, <br> <b><span style="color:#2ECC40">country %in% c("Mexico", "Canada", <br> "United States")</span></b>)</code> ] ] --- class: title title-2 # Common syntax .box-inv-2[Every dplyr verb function follows the same pattern] .box-inv-2[First argument is a data frame; returns a data frame] .pull-left[ <code class ='r hljs remark-code'><b><span style="background-color:#EFB3FF">VERB</span></b>(<b><span style="background-color:#FFDFD1">DATA</span></b>, <b><span style="background-color:#FFD0CF">...</span></b>)</code> ] .pull-right[ - <b><span style="background: #EFB3FF">`VERB`</span></b> = dplyr function/verb - <b><span style="background: #FFDFD1">`DATA`</span></b> = Data frame to transform - <b><span style="background: #FFD0CF">`...`</span></b> = Stuff the verb does ] --- class: title title-2 # `mutate()` .box-inv-2[Create new columns] .pull-left[ <code class ='r hljs remark-code'>mutate(<b><span style="background-color:#FFDFD1">DATA</span></b>, <b><span style="background-color:#FFD0CF">...</span></b>)</code> ] .pull-right[ - <b><span style="background: #FFDFD1">`DATA`</span></b> = Data frame to transform - <b><span style="background: #FFD0CF">`...`</span></b> = Columns to make ] --- <code class ='r hljs remark-code'>mutate(<b><span style="background-color:#FFDFD1">gapminder</span></b>, <b><span style="background-color:#FFD0CF">gdp = gdpPercap * pop</span></b>)</code> .pull-left.small[ <table> <thead> <tr> <th style="text-align:left;"> country </th> <th style="text-align:left;"> year </th> <th style="text-align:left;"> gdpPercap </th> <th style="text-align:left;"> pop </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> 1952 </td> <td style="text-align:left;"> 779.4453145 </td> <td style="text-align:left;"> 8425333 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> 1957 </td> <td style="text-align:left;"> 820.8530296 </td> <td style="text-align:left;"> 9240934 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> 1962 </td> <td style="text-align:left;"> 853.10071 </td> <td style="text-align:left;"> 10267083 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> 1967 </td> <td style="text-align:left;"> 836.1971382 </td> <td style="text-align:left;"> 11537966 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> 1972 </td> <td style="text-align:left;"> 739.9811058 </td> <td style="text-align:left;"> 13079460 </td> </tr> <tr> <td style="text-align:left;"> … </td> <td style="text-align:left;"> … </td> <td style="text-align:left;"> … </td> <td style="text-align:left;"> … </td> </tr> </tbody> </table> ] -- .pull-right.small[ <table> <thead> <tr> <th style="text-align:left;"> country </th> <th style="text-align:right;"> year </th> <th style="text-align:left;"> … </th> <th style="text-align:right;"> gdp </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:right;"> 1952 </td> <td style="text-align:left;"> … </td> <td style="text-align:right;"> 6567086330 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:right;"> 1957 </td> <td style="text-align:left;"> … </td> <td style="text-align:right;"> 7585448670 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:right;"> 1962 </td> <td style="text-align:left;"> … </td> <td style="text-align:right;"> 8758855797 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:right;"> 1967 </td> <td style="text-align:left;"> … </td> <td style="text-align:right;"> 9648014150 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:right;"> 1972 </td> <td style="text-align:left;"> … </td> <td style="text-align:right;"> 9678553274 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:right;"> 1977 </td> <td style="text-align:left;"> … </td> <td style="text-align:right;"> 11697659231 </td> </tr> </tbody> </table> ] --- <code class ='r hljs remark-code'>mutate(<b><span style="background-color:#FFDFD1">gapminder</span></b>, <b><span style="background-color:#FFD0CF">gdp = gdpPercap * pop,</span></b><br> <b><span style="background-color:#FFD0CF">pop_mil = round(pop / 1000000)</span></b>)</code> .pull-left.small[ <table> <thead> <tr> <th style="text-align:left;"> country </th> <th style="text-align:left;"> year </th> <th style="text-align:left;"> gdpPercap </th> <th style="text-align:left;"> pop </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> 1952 </td> <td style="text-align:left;"> 779.4453145 </td> <td style="text-align:left;"> 8425333 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> 1957 </td> <td style="text-align:left;"> 820.8530296 </td> <td style="text-align:left;"> 9240934 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> 1962 </td> <td style="text-align:left;"> 853.10071 </td> <td style="text-align:left;"> 10267083 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> 1967 </td> <td style="text-align:left;"> 836.1971382 </td> <td style="text-align:left;"> 11537966 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:left;"> 1972 </td> <td style="text-align:left;"> 739.9811058 </td> <td style="text-align:left;"> 13079460 </td> </tr> <tr> <td style="text-align:left;"> … </td> <td style="text-align:left;"> … </td> <td style="text-align:left;"> … </td> <td style="text-align:left;"> … </td> </tr> </tbody> </table> ] -- .pull-right.small[ <table> <thead> <tr> <th style="text-align:left;"> country </th> <th style="text-align:right;"> year </th> <th style="text-align:left;"> … </th> <th style="text-align:right;"> gdp </th> <th style="text-align:right;"> pop_mil </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:right;"> 1952 </td> <td style="text-align:left;"> … </td> <td style="text-align:right;"> 6567086330 </td> <td style="text-align:right;"> 8 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:right;"> 1957 </td> <td style="text-align:left;"> … </td> <td style="text-align:right;"> 7585448670 </td> <td style="text-align:right;"> 9 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:right;"> 1962 </td> <td style="text-align:left;"> … </td> <td style="text-align:right;"> 8758855797 </td> <td style="text-align:right;"> 10 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:right;"> 1967 </td> <td style="text-align:left;"> … </td> <td style="text-align:right;"> 9648014150 </td> <td style="text-align:right;"> 12 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:right;"> 1972 </td> <td style="text-align:left;"> … </td> <td style="text-align:right;"> 9678553274 </td> <td style="text-align:right;"> 13 </td> </tr> <tr> <td style="text-align:left;"> Afghanistan </td> <td style="text-align:right;"> 1977 </td> <td style="text-align:left;"> … </td> <td style="text-align:right;"> 11697659231 </td> <td style="text-align:right;"> 15 </td> </tr> </tbody> </table> ] --- class: title title-2 # `ifelse()` .box-inv-2[Do conditional tests within `mutate()`] .pull-left[ <code class ='r hljs remark-code'>ifelse(<b><span style="background-color:#FFC0DC">TEST</span></b>, <br> <b><span style="background-color:#FFDFD1">VALUE_IF_TRUE</span></b>, <br> <b><span style="background-color:#CBB5FF">VALUE_IF_FALSE</span></b>)</code> ] .pull-right[ - <b><span style="background: #FFC0DC">`TEST`</span></b> = A logical test - <b><span style="background: #FFDFD1">`VALUE_IF_TRUE`</span></b> = What happens if test is true - <b><span style="background: #CBB5FF">`VALUE_IF_FALSE`</span></b> = What happens if test is false ] --- <code class ='r hljs remark-code'>mutate(gapminder, <br> after_1960 = ifelse(<b><span style="background-color:#FFC0DC">year > 1960</span></b>, <b><span style="background-color:#FFDFD1">TRUE</span></b>, <b><span style="background-color:#CBB5FF">FALSE</span></b>))</code> <code class ='r hljs remark-code'>mutate(gapminder, <br> after_1960 = ifelse(<b><span style="background-color:#FFC0DC">year > 1960</span></b>, <br> <b><span style="background-color:#FFDFD1">"After 1960"</span></b>, <br> <b><span style="background-color:#CBB5FF">"Before 1960"</span></b>))</code> --- class: title title-2 section-title-inv-2 # Your turn #3: Mutating .box-2[Use `mutate()` to…] 1. Add an `africa` column that is TRUE if the country is on the African continent 2. Add a column for logged GDP per capita (hint: use `log()`) 3. Add an `africa_asia` column that says “Africa or Asia” if the country is in Africa or Asia, and “Not Africa or Asia” if it’s not
03
:
00
--- ```r mutate(gapminder, africa = ifelse(continent == "Africa", TRUE, FALSE)) ``` -- ```r mutate(gapminder, log_gdpPercap = log(gdpPercap)) ``` -- ```r mutate(gapminder, africa_asia = ifelse(continent %in% c("Africa", "Asia"), "Africa or Asia", "Not Africa or Asia")) ``` --- class: title title-2 # What if you have multiple verbs? .box-inv-2.sp-after[Make a dataset for just 2002 *and* calculate logged GDP per capita] -- .box-inv-2[Solution 1: Intermediate variables] <code class ='r hljs remark-code'><b><span style="background-color:#FFC0DC">gapminder_2002</span></b> <- filter(gapminder, year == 2002)<br><br><b><span style="background-color:#FFC0DC">gapminder_2002</span></b>_log <- mutate(<b><span style="background-color:#FFC0DC">gapminder_2002</span></b>,<br> log_gdpPercap = log(gdpPercap))</code> --- class: title title-2 # What if you have multiple verbs? .box-inv-2.sp-after[Make a dataset for just 2002 *and* calculate logged GDP per capita] .box-inv-2[Solution 2: Nested functions] <code class ='r hljs remark-code'><b><span style="background-color:#FFC0DC">filter(</span></b><b><span style="background-color:#FFDFD1">mutate(gapminder_2002,</span></b> <br> <b><span style="background-color:#FFDFD1">log_gdpPercap = log(gdpPercap))</span></b>, <br> <b><span style="background-color:#FFC0DC">year == 2002)</span></b></code> --- class: title title-2 # What if you have multiple verbs? .box-inv-2.sp-after[Make a dataset for just 2002 *and* calculate logged GDP per capita] .box-inv-2[Solution 3: Pipes!] .box-inv-2[The `%>%` operator (pipe) takes an object on the left<br>and passes it as the first argument of the function on the right] <code class ='r hljs remark-code'><b><span style="background-color:#FFC0DC">gapminder</span></b> %>% filter(<b><span style="background-color:#FFC0DC">_____</span></b>, country == "Canada")</code> --- class: title title-2 # What if you have multiple verbs? .box-inv-2[These do the same thing!] <code class ='r hljs remark-code'>filter(<b><span style="background-color:#FFC0DC">gapminder</span></b>, country == "Canada")</code> <code class ='r hljs remark-code'><b><span style="background-color:#FFC0DC">gapminder</span></b> %>% filter(country == "Canada")</code> --- class: title title-2 # What if you have multiple verbs? .box-inv-2.sp-after[Make a dataset for just 2002 *and* calculate logged GDP per capita] .box-inv-2[Solution 3: Pipes!] <code class ='r hljs remark-code'>gapminder %>% <br> filter(year == 2002) %>% <br> mutate(log_gdpPercap = log(gdpPercap))</code> --- class: title title-2 # `%>%` <code class ='r hljs remark-code'><b>leave_house</b>(<b>get_dressed</b>(<b>get_out_of_bed</b>(<b>wake_up</b>(<span style="color:#E16462">me</span>, <span style="color:#0D0887">time</span> = <span style="color:#E16462">"8:00"</span>), <span style="color:#0D0887">side</span> = <span style="color:#E16462">"correct"</span>), <span style="color:#0D0887">pants</span> = <span style="color:#E16462">TRUE</span>, <span style="color:#0D0887">shirt</span> = <span style="color:#E16462">TRUE</span>), <span style="color:#0D0887">car</span> = <span style="color:#E16462">TRUE</span>, <span style="color:#0D0887">bike</span> = <span style="color:#E16462">FALSE</span>)</code> -- <code class ='r hljs remark-code'>me %>% <br> <b>wake_up</b>(<span style="color:#0D0887">time</span> = <span style="color:#E16462">"8:00"</span>) %>% <br> <b>get_out_of_bed</b>(<span style="color:#0D0887">side</span> = <span style="color:#E16462">"correct"</span>) %>% <br> <b>get_dressed</b>(<span style="color:#0D0887">pants</span> = <span style="color:#E16462">TRUE</span>, <span style="color:#0D0887">shirt</span> = <span style="color:#E16462">TRUE</span>) %>% <br> <b>leave_house</b>(<span style="color:#0D0887">car</span> = <span style="color:#E16462">TRUE</span>, <span style="color:#0D0887">bike</span> = <span style="color:#E16462">FALSE</span>)</code> --- class: title title-2 # dplyr: verbs for manipulating data <table> <tr> <td>Extract rows with <code>filter()</code></td> <td><img src="img/02c/filter.png" alt="filter" title="filter" height="80px"></td> </tr> <tr> <td>Extract columns with <code>select()</code></td> <td><img src="img/02c/select.png" alt="select" title="select" height="80px"></td> </tr> <tr> <td>Arrange/sort rows with <code>arrange()</code></td> <td><img src="img/02c/arrange.png" alt="arrange" title="arrange" height="80px"></td> </tr> <tr> <td>Make new columns with <code>mutate()</code></td> <td><img src="img/02c/mutate.png" alt="mutate" title="mutate" height="80px"></td> </tr> <tr> <td>Make group summaries with<br><code>group_by() %>% summarize()</code></td> <td><img src="img/02c/summarize.png" alt="summarize" title="summarize" height="80px"></td> </tr> </table>