Import data
# csv file
data <- read_csv("../00_data/myData.csv")
data
## # A tibble: 247 × 25
## year brand superbowl_ads_dot_co…¹ youtube_url funny show_product_quickly
## <dbl> <chr> <chr> <chr> <lgl> <lgl>
## 1 2018 Toyota https://superbowl-ads… https://ww… FALSE FALSE
## 2 2020 Bud Light https://superbowl-ads… https://ww… TRUE TRUE
## 3 2006 Bud Light https://superbowl-ads… https://ww… TRUE FALSE
## 4 2018 Hynudai https://superbowl-ads… https://ww… FALSE TRUE
## 5 2003 Bud Light https://superbowl-ads… https://ww… TRUE TRUE
## 6 2020 Toyota https://superbowl-ads… https://ww… TRUE TRUE
## 7 2020 Coca-Cola https://superbowl-ads… https://ww… TRUE FALSE
## 8 2020 Kia https://superbowl-ads… https://ww… FALSE FALSE
## 9 2020 Hynudai https://superbowl-ads… https://ww… TRUE TRUE
## 10 2020 Budweiser https://superbowl-ads… https://ww… FALSE TRUE
## # ℹ 237 more rows
## # ℹ abbreviated name: ¹superbowl_ads_dot_com_url
## # ℹ 19 more variables: patriotic <lgl>, celebrity <lgl>, danger <lgl>,
## # animals <lgl>, use_sex <lgl>, id <chr>, kind <chr>, etag <chr>,
## # view_count <dbl>, like_count <dbl>, dislike_count <dbl>,
## # favorite_count <dbl>, comment_count <dbl>, published_at <dttm>,
## # title <chr>, description <chr>, thumbnail <chr>, channel_title <chr>, …
Apply the following dplyr verbs to your data
Filter rows
filter(data, brand == "Bud Light")
## # A tibble: 63 × 25
## year brand superbowl_ads_dot_co…¹ youtube_url funny show_product_quickly
## <dbl> <chr> <chr> <chr> <lgl> <lgl>
## 1 2020 Bud Light https://superbowl-ads… https://ww… TRUE TRUE
## 2 2006 Bud Light https://superbowl-ads… https://ww… TRUE FALSE
## 3 2003 Bud Light https://superbowl-ads… https://ww… TRUE TRUE
## 4 2010 Bud Light https://superbowl-ads… https://ww… TRUE FALSE
## 5 2005 Bud Light https://superbowl-ads… https://ww… TRUE TRUE
## 6 2004 Bud Light https://superbowl-ads… https://ww… TRUE TRUE
## 7 2007 Bud Light https://superbowl-ads… https://ww… TRUE TRUE
## 8 2010 Bud Light https://superbowl-ads… https://ww… TRUE FALSE
## 9 2001 Bud Light https://superbowl-ads… https://ww… TRUE TRUE
## 10 2019 Bud Light https://superbowl-ads… https://ww… TRUE TRUE
## # ℹ 53 more rows
## # ℹ abbreviated name: ¹superbowl_ads_dot_com_url
## # ℹ 19 more variables: patriotic <lgl>, celebrity <lgl>, danger <lgl>,
## # animals <lgl>, use_sex <lgl>, id <chr>, kind <chr>, etag <chr>,
## # view_count <dbl>, like_count <dbl>, dislike_count <dbl>,
## # favorite_count <dbl>, comment_count <dbl>, published_at <dttm>,
## # title <chr>, description <chr>, thumbnail <chr>, channel_title <chr>, …
Arrange rows
arrange(data, celebrity)
## # A tibble: 247 × 25
## year brand superbowl_ads_dot_co…¹ youtube_url funny show_product_quickly
## <dbl> <chr> <chr> <chr> <lgl> <lgl>
## 1 2018 Toyota https://superbowl-ads… https://ww… FALSE FALSE
## 2 2006 Bud Light https://superbowl-ads… https://ww… TRUE FALSE
## 3 2018 Hynudai https://superbowl-ads… https://ww… FALSE TRUE
## 4 2003 Bud Light https://superbowl-ads… https://ww… TRUE TRUE
## 5 2010 Hynudai https://superbowl-ads… https://ww… FALSE TRUE
## 6 2010 Bud Light https://superbowl-ads… https://ww… TRUE FALSE
## 7 2007 Budweiser https://superbowl-ads… https://ww… TRUE TRUE
## 8 2002 Budweiser https://superbowl-ads… https://ww… FALSE TRUE
## 9 2017 NFL https://superbowl-ads… https://ww… FALSE TRUE
## 10 2005 Bud Light https://superbowl-ads… https://ww… TRUE TRUE
## # ℹ 237 more rows
## # ℹ abbreviated name: ¹superbowl_ads_dot_com_url
## # ℹ 19 more variables: patriotic <lgl>, celebrity <lgl>, danger <lgl>,
## # animals <lgl>, use_sex <lgl>, id <chr>, kind <chr>, etag <chr>,
## # view_count <dbl>, like_count <dbl>, dislike_count <dbl>,
## # favorite_count <dbl>, comment_count <dbl>, published_at <dttm>,
## # title <chr>, description <chr>, thumbnail <chr>, channel_title <chr>, …
Select columns
select(data, year, brand, patriotic, use_sex)
## # A tibble: 247 × 4
## year brand patriotic use_sex
## <dbl> <chr> <lgl> <lgl>
## 1 2018 Toyota FALSE FALSE
## 2 2020 Bud Light FALSE FALSE
## 3 2006 Bud Light FALSE FALSE
## 4 2018 Hynudai FALSE FALSE
## 5 2003 Bud Light FALSE TRUE
## 6 2020 Toyota FALSE FALSE
## 7 2020 Coca-Cola FALSE FALSE
## 8 2020 Kia FALSE FALSE
## 9 2020 Hynudai FALSE FALSE
## 10 2020 Budweiser TRUE FALSE
## # ℹ 237 more rows
Add columns
mutate(data,
gain = 2018 - 2020)
## # A tibble: 247 × 26
## year brand superbowl_ads_dot_co…¹ youtube_url funny show_product_quickly
## <dbl> <chr> <chr> <chr> <lgl> <lgl>
## 1 2018 Toyota https://superbowl-ads… https://ww… FALSE FALSE
## 2 2020 Bud Light https://superbowl-ads… https://ww… TRUE TRUE
## 3 2006 Bud Light https://superbowl-ads… https://ww… TRUE FALSE
## 4 2018 Hynudai https://superbowl-ads… https://ww… FALSE TRUE
## 5 2003 Bud Light https://superbowl-ads… https://ww… TRUE TRUE
## 6 2020 Toyota https://superbowl-ads… https://ww… TRUE TRUE
## 7 2020 Coca-Cola https://superbowl-ads… https://ww… TRUE FALSE
## 8 2020 Kia https://superbowl-ads… https://ww… FALSE FALSE
## 9 2020 Hynudai https://superbowl-ads… https://ww… TRUE TRUE
## 10 2020 Budweiser https://superbowl-ads… https://ww… FALSE TRUE
## # ℹ 237 more rows
## # ℹ abbreviated name: ¹superbowl_ads_dot_com_url
## # ℹ 20 more variables: patriotic <lgl>, celebrity <lgl>, danger <lgl>,
## # animals <lgl>, use_sex <lgl>, id <chr>, kind <chr>, etag <chr>,
## # view_count <dbl>, like_count <dbl>, dislike_count <dbl>,
## # favorite_count <dbl>, comment_count <dbl>, published_at <dttm>,
## # title <chr>, description <chr>, thumbnail <chr>, channel_title <chr>, …
Summarize by groups
data %>%
#group by brand
group_by(brand)
## # A tibble: 247 × 25
## # Groups: brand [10]
## year brand superbowl_ads_dot_co…¹ youtube_url funny show_product_quickly
## <dbl> <chr> <chr> <chr> <lgl> <lgl>
## 1 2018 Toyota https://superbowl-ads… https://ww… FALSE FALSE
## 2 2020 Bud Light https://superbowl-ads… https://ww… TRUE TRUE
## 3 2006 Bud Light https://superbowl-ads… https://ww… TRUE FALSE
## 4 2018 Hynudai https://superbowl-ads… https://ww… FALSE TRUE
## 5 2003 Bud Light https://superbowl-ads… https://ww… TRUE TRUE
## 6 2020 Toyota https://superbowl-ads… https://ww… TRUE TRUE
## 7 2020 Coca-Cola https://superbowl-ads… https://ww… TRUE FALSE
## 8 2020 Kia https://superbowl-ads… https://ww… FALSE FALSE
## 9 2020 Hynudai https://superbowl-ads… https://ww… TRUE TRUE
## 10 2020 Budweiser https://superbowl-ads… https://ww… FALSE TRUE
## # ℹ 237 more rows
## # ℹ abbreviated name: ¹superbowl_ads_dot_com_url
## # ℹ 19 more variables: patriotic <lgl>, celebrity <lgl>, danger <lgl>,
## # animals <lgl>, use_sex <lgl>, id <chr>, kind <chr>, etag <chr>,
## # view_count <dbl>, like_count <dbl>, dislike_count <dbl>,
## # favorite_count <dbl>, comment_count <dbl>, published_at <dttm>,
## # title <chr>, description <chr>, thumbnail <chr>, channel_title <chr>, …