Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R_basis
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LBMC
Hub
formations
R_basis
Commits
fc54ef09
Verified
Commit
fc54ef09
authored
3 years ago
by
Laurent Modolo
Browse files
Options
Downloads
Patches
Plain Diff
fix session_5.Rmd name
parent
a36ca9f8
No related branches found
No related tags found
3 merge requests
!6
Switch to main as default branch
,
!4
update contributing
,
!3
Carine dev
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
session_5/session_5.Rmd
+9
-5
9 additions, 5 deletions
session_5/session_5.Rmd
with
9 additions
and
5 deletions
session_5/sess
s
ion_5.Rmd
→
session_5/session_5.Rmd
+
9
−
5
View file @
fc54ef09
---
title: "R
#
5: Pipping and grouping"
author: "Laurent Modolo [laurent.modolo@ens-lyon.fr](mailto:laurent.modolo@ens-lyon.fr)
title: "R
.
5: Pipping and grouping"
author: "Laurent Modolo [laurent.modolo@ens-lyon.fr](mailto:laurent.modolo@ens-lyon.fr)
"
date: "2021"
output:
rmdformats::downcute:
...
...
@@ -116,7 +116,7 @@ Then, when you use the function you already know on grouped data frame and they
You can use the following code to compute the average delay per months across years.
```{r summarise_group_by, include=TRUE, fig.width=8, fig.height=3.5}
```{r summarise_group_by, include=TRUE,
message=FALSE,
fig.width=8, fig.height=3.5}
flights_delay <- flights %>%
group_by(year, month) %>%
summarise(delay = mean(dep_delay, na.rm = TRUE), sd = sd(dep_delay, na.rm = TRUE)) %>%
...
...
@@ -138,6 +138,8 @@ Why did we `group_by` `year` and `month` and not only `year` ?
You may have wondered about the `na.rm` argument we used above. What happens if we don’t set it?
</div>
<details><summary>Solution</summary>
<p>
```{r summarise_group_by_NA, include=TRUE}
flights %>%
group_by(dest) %>%
...
...
@@ -146,6 +148,8 @@ flights %>%
delay = mean(arr_delay)
)
```
</p>
</details>
Aggregation functions obey the usual rule of missing values: **if there’s any missing value in the input, the output will be a missing value**.
...
...
@@ -361,7 +365,7 @@ Which carrier has the worst delays?
<details><summary>Solution</summary>
<p>
```{r grouping_challenges_c, eval=F, echo = T, message=FALSE, cache=T}
```{r grouping_challenges_c
1
, eval=F, echo = T, message=FALSE, cache=T}
flights %>%
group_by(carrier) %>%
summarise(
...
...
@@ -380,7 +384,7 @@ Can you disentangle the effects of bad airports vs. bad carriers? (Hint: think a
<details><summary>Solution</summary>
<p>
```{r grouping_challenges_c, eval=F, echo = T, message=FALSE, cache=T}
```{r grouping_challenges_c
2
, eval=F, echo = T, message=FALSE, cache=T}
flights %>%
group_by(carrier, dest) %>%
summarise(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment