Copy and run Copy and run the following code chunk:

by_country <- group_by(tb_long, country)
by_country
## # A tibble: 157,820 x 7
## # Groups:   country [219]
##    country     iso3   year type   sex   age_group count
##    <chr>       <chr> <dbl> <chr>  <chr> <chr>     <dbl>
##  1 Afghanistan AFG    1980 new_sp m     04           NA
##  2 Afghanistan AFG    1981 new_sp m     04           NA
##  3 Afghanistan AFG    1982 new_sp m     04           NA
##  4 Afghanistan AFG    1983 new_sp m     04           NA
##  5 Afghanistan AFG    1984 new_sp m     04           NA
##  6 Afghanistan AFG    1985 new_sp m     04           NA
##  7 Afghanistan AFG    1986 new_sp m     04           NA
##  8 Afghanistan AFG    1987 new_sp m     04           NA
##  9 Afghanistan AFG    1988 new_sp m     04           NA
## 10 Afghanistan AFG    1989 new_sp m     04           NA
## # ... with 157,810 more rows

Output matches expected output provided

Summarise example

summarise(by_country,
          min = min(count, na.rm = TRUE),
          first_quartile = quantile(count, 0.25, na.rm = TRUE),
          median = median(count, na.rm = TRUE),
          third_quartile = quantile(count, 0.75, na.rm = TRUE),
          max = max(count, na.rm = TRUE))
## # A tibble: 219 x 6
##    country               min first_quartile median third_quartile   max
##    <chr>               <dbl>          <dbl>  <dbl>          <dbl> <dbl>
##  1 Afghanistan             0           139    419            772.  2449
##  2 Albania                 0             2     10             19     43
##  3 Algeria                 0           243.   378.           825.  1982
##  4 American Samoa          0             0      0              0      2
##  5 Andorra                 0             0      0              0      6
##  6 Angola                  0           386.   684.          1592.  3792
##  7 Anguilla                0             0      0              0      1
##  8 Antigua and Barbuda     0             0      0              0      3
##  9 Argentina               1           130    294.           466.   682
## 10 Armenia                 0             2     11             36    170
## # ... with 209 more rows

Output matches expected output provided

This is where the replication stops working

max_cases <- filter(by_country, count == max(count, na.rm = TRUE)) %>% 
  arrange((country))
max_cases
## # A tibble: 364 x 7
## # Groups:   country [219]
##    country        iso3   year type   sex   age_group count
##    <chr>          <chr> <dbl> <chr>  <chr> <chr>     <dbl>
##  1 Afghanistan    AFG    2008 new_sp f     2534       2449
##  2 Albania        ALB    1997 new_sp m     2534         43
##  3 Algeria        DZA    1997 new_sp m     2534       1982
##  4 American Samoa ASM    2004 new_sp m     5564          2
##  5 American Samoa ASM    2005 new_sp f     4554          2
##  6 American Samoa ASM    2006 new_sp f     4554          2
##  7 Andorra        AND    1997 new_sp m     65            6
##  8 Angola         AGO    2011 new_sp m     2534       3792
##  9 Anguilla       AIA    2010 new_sp m     65            1
## 10 Anguilla       AIA    2003 new_sp f     3544          1
## # ... with 354 more rows

Output does not match expected output. Expected output is

## # A tibble: 364 x 7
## # Groups:   country [219]
##    country        iso3   year type   sex   age_group count
##    <chr>          <chr> <dbl> <chr>  <chr> <chr>     <dbl>
##  1 Afghanistan    AFG    2008 new_sp f     2534       2449
##  2 Albania        ALB    1997 new_sp m     2534         43
##  3 Algeria        DZA    1997 new_sp m     2534       1982
##  4 American Samoa ASM    2004 new_sp m     5564          2
##  5 American Samoa ASM    2005 new_sp f     4554          2
##  6 American Samoa ASM    2006 new_sp f     4554          2
##  7 Andorra        AND    1997 new_sp m     65            6
##  8 Angola         AGO    2011 new_sp m     2534       3792
##  9 Anguilla       AIA    2003 new_sp f     3544          1
## 10 Anguilla       AIA    2010 new_sp m     65            1
## # … with 354 more rows

Expected output can be replicated by adding an arrange

max_cases <- filter(by_country, count == max(count, na.rm = TRUE)) %>% 
  arrange(country)
max_cases
## # A tibble: 364 x 7
## # Groups:   country [219]
##    country        iso3   year type   sex   age_group count
##    <chr>          <chr> <dbl> <chr>  <chr> <chr>     <dbl>
##  1 Afghanistan    AFG    2008 new_sp f     2534       2449
##  2 Albania        ALB    1997 new_sp m     2534         43
##  3 Algeria        DZA    1997 new_sp m     2534       1982
##  4 American Samoa ASM    2004 new_sp m     5564          2
##  5 American Samoa ASM    2005 new_sp f     4554          2
##  6 American Samoa ASM    2006 new_sp f     4554          2
##  7 Andorra        AND    1997 new_sp m     65            6
##  8 Angola         AGO    2011 new_sp m     2534       3792
##  9 Anguilla       AIA    2010 new_sp m     65            1
## 10 Anguilla       AIA    2003 new_sp f     3544          1
## # ... with 354 more rows

```