AFI 2.4

Author

Vanessa Lade

library(tidyverse)

Begin by loading the tidyverse package in the code chunk above and adding your name as the author.

The readr package includes functions for reading tabular data into R. Each code chuck below should read in the specified data file, storing it in an appropriately named object, and then print the data. The data are stored in the data folder.

Importing Data

Let’s start by reading in the AllCountries.csv data. Modify this code by filling in the ______ to do so:

all_countries <- read_csv("data/AllCountries.csv")
all_countries
# A tibble: 217 × 25
   Country      LandArea Population Density   GDP Rural   CO2 PumpPrice Military
   <chr>           <dbl>      <dbl>   <dbl> <dbl> <dbl> <dbl>     <dbl>    <dbl>
 1 Afghanistan    653.       30.6      46.8   665  74.1  35.3      1.28     8.65
 2 Albania         27.4       2.90    106.   4460  44.6  12.8      1.81    NA   
 3 Algeria       2382.       39.2      16.5  5361  30.5  24.6      0.29    NA   
 4 American Sa…     0.2       0.055   275      NA  12.7  NA       NA       NA   
 5 Andorra          0.47      0.079   168.     NA  13.8   9.5      1.67    NA   
 6 Angola        1247.       21.5      17.2  5783  57.5  44.8      0.63    13.8 
 7 Antigua and…     0.44      0.09    204.  13342  75.4  16.6     NA       NA   
 8 Argentina     2737.       41.4      15.1 14715   8.5  16.9      1.46    NA   
 9 Armenia         28.5       2.98    105.   3505  37    13.9      1.25    16.8 
10 Aruba            0.18      0.103   572.     NA  57.9  10.4     NA       NA   
# ℹ 207 more rows
# ℹ 16 more variables: Health <dbl>, ArmedForces <dbl>, Internet <dbl>,
#   Cell <dbl>, HIV <dbl>, Hunger <dbl>, Diabetes <dbl>, BirthRate <dbl>,
#   DeathRate <dbl>, ElderlyPop <dbl>, LifeExpectancy <dbl>, FemaleLabor <dbl>,
#   Unemployment <dbl>, EnergyUse <dbl>, Electricity <dbl>, Developed <dbl>

That was easy, right? Note that including the #| message: false at the beginning of the code chunk suppresses unneeded messages and cleans up your output for whoever reads it (me!).

Now try the minn_stp_weather.csv data:

minn_stp_weather <- read_csv("data/minn_stp_weather.csv")
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
  dat <- vroom(...)
  problems(dat)
minn_stp_weather
# A tibble: 1,403 × 2
   `Description: Monthly weather data for Minneapolis-St. Paul` Minnesota
   <chr>                                                        <chr>    
 1 for 1/1900-12/2014.                                          <NA>     
 2 Variables:                                                   <NA>     
 3 MonthY   (Month of the year 1-12)                            <NA>     
 4 MonthS   (Month of the Series 1-1380)                        <NA>     
 5 Year                                                         <NA>     
 6 LowTemp                                                      <NA>     
 7 HighTemp                                                     <NA>     
 8 WarmestMin   (Warmest daily low temp)                        <NA>     
 9 ColdestHigh   (Coldest daily high temp)                      <NA>     
10 AveMin                                                       <NA>     
# ℹ 1,393 more rows

Did you look at the data file before trying?

No. 

Now try the white_nonhisp_death_rates_from_1999_to_2013.txt data:

white_nonhisp_death_rates_from_1999_to_2013 <- read_table(
  "data/white_nonhisp_death_rates_from_1999_to_2013.txt"
)
white_nonhisp_death_rates_from_1999_to_2013
# A tibble: 150 × 5
     Age  Year Deaths Population  Rate
   <dbl> <dbl>  <dbl>      <dbl> <dbl>
 1    45  1999   8304    3166393  262.
 2    45  2000   8604    3207271  268.
 3    45  2001   8836    3152637  280.
 4    45  2002   9217    3256317  283 
 5    45  2003   9287    3260376  285.
 6    45  2004   9210    3211340  287.
 7    45  2005   9352    3279109  285.
 8    45  2006   9100    3222835  282.
 9    45  2007   8805    3137876  281.
10    45  2008   8751    3074171  285.
# ℹ 140 more rows

Here’s a trickier one. Read in the deaton.txt data:

deaton <- read_table("data/deaton.txt")
deaton
# A tibble: 10 × 4
     age death_rate_1989 death_rate_2013 change
   <dbl>           <dbl>           <dbl>  <dbl>
 1    45            262.            261.   -1.6
 2    46            293.            290.   -3.1
 3    47            306.            324.   17.6
 4    48            337.            343.    5.7
 5    49            359             384.   25.5
 6    50            377.            422.   45.5
 7    51            429             466.   37.1
 8    52            445.            481.   36.4
 9    53            545.            527.  -18.4
10    54            555.            573.   17.4

You might need to search for a function that wasn’t discussed.

Now read in the pga2004.csv data (the help page for read_csv might be useful):

pga2004 <- read_csv("data/pga2004.csv")
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
  dat <- vroom(...)
  problems(dat)
pga2004
# A tibble: 209 × 11
   `Aaron Baddeley`  `23` `288` `53.1` `58.2` `1.767` `50.9` `123`  `27`
   <chr>            <dbl> <dbl>  <dbl>  <dbl>   <dbl>  <dbl> <dbl> <dbl>
 1 Adam Scott          24  295.   57.7   65.6    1.76   59.3     7    16
 2 Alex Cejka          34  286.   64.2   63.8    1.80   50.7    54    24
 3 Andre Stolz         34  298.   59     63      1.79   47.7   101    20
 4 Arjun Atwal         31  289.   60.5   62.5    1.77   43.5   146    30
 5 Arron Oberholser    29  285.   68.8   67      1.78   50.9    52    23
 6 Bart Bryant         42  282.   74.2   68.9    1.78   40.4    80    23
 7 Ben Crane           28  284.   64.4   64.2    1.74   53.8    75    27
 8 Ben Curtis          27  282.   64.3   63.4    1.81   42.2   141    20
 9 Bernhard Langer     47  282.   62.6   65.3    1.78   47.7    83    15
10 Billy Andrade       40  284.   59.7   64.4    1.77   50.5   124    31
# ℹ 199 more rows
# ℹ 2 more variables: `632878` <dbl>, `23440` <dbl>

Lastly, read in the noise.txt data:

noise <- read_csv("data/noise.txt")

noise
# A tibble: 3,020 × 1
   `V1 V2 V3 V4 V5`                                                             
   <chr>                                                                        
 1 1 -0.674583930909611 0.831287660961015 -1.24212196465848 0.207483535687254 0…
 2 2 0.9737472992918 -0.0118044512270401 -0.415234630368159 0.192495015519491 -…
 3 3 -0.745226881760662 -1.03114509749129 1.78710569216251 0.464302036950123 -1…
 4 4 1.06163664849448 1.00958521472859 -0.202877765369821 -0.550369906854218 1.…
 5 5 0.492782786205532 -0.215364971329331 -0.191875224661116 -1.83902546788068 …
 6 6 -1.2072784130106 -0.873392756079252 0.582419482473343 -0.189547568883537 -…
 7 7 1.99768501253483 0.621711822281622 -0.966673820171751 -1.71122367517864 -0…
 8 8 -0.0599937101264524 0.91960439642132 -0.430641870570379 0.349880789746056 …
 9 9 -1.13247538142871 -0.0190390004637152 -0.430389888581933 -1.12050311157294…
10 10 0.988329892472983 -0.322441070888538 -0.00720147179076961 -1.356605924592…
# ℹ 3,010 more rows