introduction to dplyr

Code and text for Quiz 3

Grant Morley
2022-02-15

Load our packages

Read data to R

corp_tax <- read_excel(here("corp_tax.xlsx"))

Lets look at DISH Network in corp_tax

result <- corp_tax %>% 
  filter(company =='DISH Network')
result
# A tibble: 1 x 5
  company      profit   tax tax_rate industry          
  <chr>         <dbl> <dbl>    <dbl> <chr>             
1 DISH Network  2145.  44.5   0.0207 Telecommunications

DISH Network is in the Telecommunications industry. it had a profit of $2145.257 million and a tax of $44.451 million. Its tax rate was 2.1%


Finding the company in Food & beverages & tobacco with the highest profit

result <- corp_tax %>% 
  filter(industry == "Food & beverages & tobacco") %>% 
  slice_max(profit, n=1)
result
# A tibble: 1 x 5
  company      profit   tax tax_rate industry                  
  <chr>         <dbl> <dbl>    <dbl> <chr>                     
1 Altria Group   8922  1911    0.214 Food & beverages & tobacco

NVR is in the Altria Group is the company in Food & beverages & tobacco with the highest profit. it had a profit of $8922 million and a tax of $1911 million. Its tax rate was 21.4%