BC3203

Question 1: Your answer should be a function called gapminder_1972. When run like this;

gapminder_1972(gapminder)

it should produce the following outputs;

## # A tibble: 142 × 6
##    country     continent  year lifeExp      pop gdpPercap
##    <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
##  1 Afghanistan Asia       1972    36.1 13079460      740.
##  2 Albania     Europe     1972    67.7  2263554     3313.
##  3 Algeria     Africa     1972    54.5 14760787     4183.
##  4 Angola      Africa     1972    37.9  5894858     5473.
##  5 Argentina   Americas   1972    67.1 24779799     9443.
##  6 Australia   Oceania    1972    71.9 13177000    16789.
##  7 Austria     Europe     1972    70.6  7544201    16662.
##  8 Bahrain     Asia       1972    63.3   230800    18269.
##  9 Bangladesh  Asia       1972    45.3 70759295      630.
## 10 Belgium     Europe     1972    71.4  9709100    16672.
## # ℹ 132 more rows

Question 2: Your answer should be a function called gdp. When run like this;

gdp(gapminder)

it should produce the following outputs;

## # A tibble: 1,704 × 7
##    country     continent  year lifeExp      pop gdpPercap          gdp
##    <fct>       <fct>     <int>   <dbl>    <int>     <dbl>        <dbl>
##  1 Afghanistan Asia       1952    28.8  8425333      779.  6567086330.
##  2 Afghanistan Asia       1957    30.3  9240934      821.  7585448670.
##  3 Afghanistan Asia       1962    32.0 10267083      853.  8758855797.
##  4 Afghanistan Asia       1967    34.0 11537966      836.  9648014150.
##  5 Afghanistan Asia       1972    36.1 13079460      740.  9678553274.
##  6 Afghanistan Asia       1977    38.4 14880372      786. 11697659231.
##  7 Afghanistan Asia       1982    39.9 12881816      978. 12598563401.
##  8 Afghanistan Asia       1987    40.8 13867957      852. 11820990309.
##  9 Afghanistan Asia       1992    41.7 16317921      649. 10595901589.
## 10 Afghanistan Asia       1997    41.8 22227415      635. 14121995875.
## # ℹ 1,694 more rows

Question 3: Your answer should be a function called gdp_2007. When run like this;

gdp_2007(gapminder)

it should produce the following outputs;

## # A tibble: 142 × 7
##    country     continent  year lifeExp       pop gdpPercap           gdp
##    <fct>       <fct>     <int>   <dbl>     <int>     <dbl>         <dbl>
##  1 Afghanistan Asia       2007    43.8  31889923      975.  31079291949.
##  2 Albania     Europe     2007    76.4   3600523     5937.  21376411360.
##  3 Algeria     Africa     2007    72.3  33333216     6223. 207444851958.
##  4 Angola      Africa     2007    42.7  12420476     4797.  59583895818.
##  5 Argentina   Americas   2007    75.3  40301927    12779. 515033625357.
##  6 Australia   Oceania    2007    81.2  20434176    34435. 703658358894.
##  7 Austria     Europe     2007    79.8   8199783    36126. 296229400691.
##  8 Bahrain     Asia       2007    75.6    708573    29796.  21112675360.
##  9 Bangladesh  Asia       2007    64.1 150448339     1391. 209311822134.
## 10 Belgium     Europe     2007    79.4  10392226    33693. 350141166520.
## # ℹ 132 more rows

Question 4: Your answer should be a plot that looks like this;

plot of chunk unnamed-chunk-7

Question 5: Your answer should be a plot that looks like this;

plot of chunk unnamed-chunk-8

Question 6: Your answer should be a plot that looks like this;

plot of chunk unnamed-chunk-9

Question 7: Your answer should be a plot that looks like this;

plot of chunk unnamed-chunk-10

Question 8: Your answer should be a function called without_droids. When run like this;

without_droids(starwars)

it should produce the following outputs;

## # A tibble: 77 × 14
##    name     height  mass hair_color skin_color eye_color birth_year sex   gender
##    <chr>     <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> <chr> 
##  1 Luke Sk…    172    77 blond      fair       blue            19   male  mascu…
##  2 Darth V…    202   136 none       white      yellow          41.9 male  mascu…
##  3 Leia Or…    150    49 brown      light      brown           19   fema… femin…
##  4 Owen La…    178   120 brown, gr… light      blue            52   male  mascu…
##  5 Beru Wh…    165    75 brown      light      blue            47   fema… femin…
##  6 Biggs D…    183    84 black      light      brown           24   male  mascu…
##  7 Obi-Wan…    182    77 auburn, w… fair       blue-gray       57   male  mascu…
##  8 Anakin …    188    84 blond      fair       blue            41.9 male  mascu…
##  9 Wilhuff…    180    NA auburn, g… fair       blue            64   male  mascu…
## 10 Chewbac…    228   112 brown      unknown    blue           200   male  mascu…
## # ℹ 67 more rows
## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>,
## #   vehicles <list>, starships <list>

Question 9: Your answer should be a function called add_bmi. It adds a column called bmi according to this formula.

BMI

When run like this;

add_bmi(starwars)

it should produce the following outputs;

## # A tibble: 87 × 15
##    name     height  mass hair_color skin_color eye_color birth_year sex   gender
##    <chr>     <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> <chr> 
##  1 Luke Sk…    172    77 blond      fair       blue            19   male  mascu…
##  2 C-3PO       167    75 <NA>       gold       yellow         112   none  mascu…
##  3 R2-D2        96    32 <NA>       white, bl… red             33   none  mascu…
##  4 Darth V…    202   136 none       white      yellow          41.9 male  mascu…
##  5 Leia Or…    150    49 brown      light      brown           19   fema… femin…
##  6 Owen La…    178   120 brown, gr… light      blue            52   male  mascu…
##  7 Beru Wh…    165    75 brown      light      blue            47   fema… femin…
##  8 R5-D4        97    32 <NA>       white, red red             NA   none  mascu…
##  9 Biggs D…    183    84 black      light      brown           24   male  mascu…
## 10 Obi-Wan…    182    77 auburn, w… fair       blue-gray       57   male  mascu…
## # ℹ 77 more rows
## # ℹ 6 more variables: homeworld <chr>, species <chr>, films <list>,
## #   vehicles <list>, starships <list>, bmi <dbl>

Question 10: Your answer should produce a tibble that looks like this;

## # A tibble: 87 × 3
##    name               height  mass
##    <chr>               <int> <dbl>
##  1 Luke Skywalker        172    77
##  2 C-3PO                 167    75
##  3 R2-D2                  96    32
##  4 Darth Vader           202   136
##  5 Leia Organa           150    49
##  6 Owen Lars             178   120
##  7 Beru Whitesun Lars    165    75
##  8 R5-D4                  97    32
##  9 Biggs Darklighter     183    84
## 10 Obi-Wan Kenobi        182    77
## # ℹ 77 more rows

Question 11: Your answer should produce a tibble that looks like this;

## # A tibble: 49 × 2
##    homeworld      total_mass
##    <chr>               <dbl>
##  1 Alderaan               NA
##  2 Aleen Minor            15
##  3 Bespin                 79
##  4 Bestine IV            110
##  5 Cato Neimoidia         90
##  6 Cerea                  82
##  7 Champala               NA
##  8 Chandrila              NA
##  9 Concord Dawn           79
## 10 Corellia              157
## # ℹ 39 more rows

Question 12: Your answer should produce a tibble that looks like this;

## # A tibble: 3 × 2
##   gender    num_characters
##   <chr>              <int>
## 1 feminine              17
## 2 masculine             66
## 3 <NA>                   4

Question 13: Your answer should produce a tibble that looks like this;

## # A tibble: 176 × 4
##    name             species      stat       value
##    <chr>            <chr>        <chr>      <dbl>
##  1 Ackbar           Mon Calamari birth_year  41  
##  2 Ackbar           Mon Calamari height     180  
##  3 Ackbar           Mon Calamari mass        83  
##  4 Adi Gallia       Tholothian   height     184  
##  5 Adi Gallia       Tholothian   mass        50  
##  6 Anakin Skywalker Human        birth_year  41.9
##  7 Anakin Skywalker Human        height     188  
##  8 Anakin Skywalker Human        mass        84  
##  9 Ayla Secura      Twi'lek      birth_year  48  
## 10 Ayla Secura      Twi'lek      height     178  
## # ℹ 166 more rows

Question 14: Your answer should be a plot that looks like this;

plot of chunk unnamed-chunk-21