library(readr)
df <- read_csv("Scooby-Doo Complete - Episode List - Update 9 15 21.csv")
## Rows: 604 Columns: 75
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (61): series.name, network, season, title, imdb, engagement, date.aired,...
## dbl  (5): index, run.time, monster.amount, suspects.amount, culprit.amount
## lgl  (9): unmask.other, caught.other, caught.not, door.gag, batman, scooby-d...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
mean(df$suspects.amount)
## [1] 2.850993
mean(df$run.time, na.rm = TRUE)
## [1] 23.61093
mean(df$run.time)
## [1] 23.61093

()


```r
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ purrr     1.0.2
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
data()
view(mpg)
glimpse(mpg)
## Rows: 234
## Columns: 11
## $ manufacturer <chr> "audi", "audi", "audi", "audi", "audi", "audi", "audi", "…
## $ model        <chr> "a4", "a4", "a4", "a4", "a4", "a4", "a4", "a4 quattro", "…
## $ displ        <dbl> 1.8, 1.8, 2.0, 2.0, 2.8, 2.8, 3.1, 1.8, 1.8, 2.0, 2.0, 2.…
## $ year         <int> 1999, 1999, 2008, 2008, 1999, 1999, 2008, 1999, 1999, 200…
## $ cyl          <int> 4, 4, 4, 4, 6, 6, 6, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 8, 8, …
## $ trans        <chr> "auto(l5)", "manual(m5)", "manual(m6)", "auto(av)", "auto…
## $ drv          <chr> "f", "f", "f", "f", "f", "f", "f", "4", "4", "4", "4", "4…
## $ cty          <int> 18, 21, 20, 21, 16, 18, 18, 18, 16, 20, 19, 15, 17, 17, 1…
## $ hwy          <int> 29, 29, 31, 30, 26, 26, 27, 26, 25, 28, 27, 25, 25, 25, 2…
## $ fl           <chr> "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p…
## $ class        <chr> "compact", "compact", "compact", "compact", "compact", "c…
mpg_ford <- filter(mpg, manufacturer == "ford")
View(mpg_ford)
mpg_metric <- mutate(mpg, cty_metric = 0.425144*cty)
glimpse(mpg_metric)
## Rows: 234
## Columns: 12
## $ manufacturer <chr> "audi", "audi", "audi", "audi", "audi", "audi", "audi", "…
## $ model        <chr> "a4", "a4", "a4", "a4", "a4", "a4", "a4", "a4 quattro", "…
## $ displ        <dbl> 1.8, 1.8, 2.0, 2.0, 2.8, 2.8, 3.1, 1.8, 1.8, 2.0, 2.0, 2.…
## $ year         <int> 1999, 1999, 2008, 2008, 1999, 1999, 2008, 1999, 1999, 200…
## $ cyl          <int> 4, 4, 4, 4, 6, 6, 6, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 8, 8, …
## $ trans        <chr> "auto(l5)", "manual(m5)", "manual(m6)", "auto(av)", "auto…
## $ drv          <chr> "f", "f", "f", "f", "f", "f", "f", "4", "4", "4", "4", "4…
## $ cty          <int> 18, 21, 20, 21, 16, 18, 18, 18, 16, 20, 19, 15, 17, 17, 1…
## $ hwy          <int> 29, 29, 31, 30, 26, 26, 27, 26, 25, 28, 27, 25, 25, 25, 2…
## $ fl           <chr> "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p…
## $ class        <chr> "compact", "compact", "compact", "compact", "compact", "c…
## $ cty_metric   <dbl> 7.652592, 8.928024, 8.502880, 8.928024, 6.802304, 7.65259…
mpg_metric <- mpg %>% 
  mutate(cty_metric = 0.425144*cty)
View(mpg)
mpg %>%
  group_by(class) %>%
summarise(mean(cty), median(cty))
## # A tibble: 7 × 3
##   class      `mean(cty)` `median(cty)`
##   <chr>            <dbl>         <dbl>
## 1 2seater           15.4            15
## 2 compact           20.1            20
## 3 midsize           18.8            18
## 4 minivan           15.8            16
## 5 pickup            13              13
## 6 subcompact        20.4            19
## 7 suv               13.5            13

Data viz with ggplot2()

ggplot(mpg, aes( x = cty)) + geom_histogram() + labs(x = "city mileage")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot(mpg, aes( x = cty)) + geom_freqpoly() + labs(x = "city mileage")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot(mpg, aes(x = cty, y = hwy)) + geom_point()

ggplot(mpg, aes(x = cty, y = hwy)) + geom_point()+ geom_smooth(method = "lm")
## `geom_smooth()` using formula = 'y ~ x'

ggplot(mpg, aes(x = cty, y = hwy, color = class)) + geom_point()

ggplot(mpg, aes(x = cty, y = hwy, color = class)) + geom_point()+ scale_color_brewer(palette = "Dark2" )