+ - 0:00:00
Notes for current slide
Notes for next slide

Session 5

1

The pipe operator

  • It can be written as %>% or |>

  • Makes your code more clear

mutate(x, y=x+1)
# same as
x %>%
mutate(y=x+1)
# or
x |>
mutate(y=x+1)
  • Use a keyboard shortcut to put it in a script!

  • In my mac is Ctrl+Shift m

2

Why?

  • With the pipe operator we can chain multiple functions together.

  • Calculate mean total points grouped by playoffs.

nba <- readRDS('./nba.rds')
nba_grouped <- group_by(nba, Playoff)
nba_summary <- summarize(nba_grouped,
avg_pts=mean(PTS))
nba_summary <- readRDS('./nba.rds') %>%
group_by(Playoff) %>%
summarize(avg_pts=mean(PTS))
3

Rmarkdown

  • File format for reports.

  • It combines R code and text.

  • It generates documents (pdf, word, html).

4

Create a file inside your project

5

Contents

  • Line 11 is text (level 2 header).

  • Line 15 is regular text.

  • Lines 17-19 are R code

6

Rmarkdown

  • R code chunks appear between 3 backticks (`).

  • When we run the file, R runs all the code inside this chunks and puts the output in the final document.

  • Ctrl+Shift+i inserts a code chunk.

  • Outside the tags, your can use markdown

7

Knit

  • Press the knit button to generate the final document (pdf, word or html file).

8

The pipe operator

  • It can be written as %>% or |>

  • Makes your code more clear

mutate(x, y=x+1)
# same as
x %>%
mutate(y=x+1)
# or
x |>
mutate(y=x+1)
  • Use a keyboard shortcut to put it in a script!

  • In my mac is Ctrl+Shift m

2
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow