library(tidyverse)AFI 2.4
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_tsv("/cloud/project/data/AllCountries.csv")
all_countries# A tibble: 217 × 1
Country,LandArea,Population,Density,GDP,Rural,CO2,PumpPrice,Military,Health…¹
<chr>
1 Afghanistan,652.860,30.552,46.8,665,74.1,35.3,1.28,8.65,7.07,330.65,5.9,70.7…
2 Albania,27.400,2.897,105.7,4460,44.6,12.8,1.81,,9.85,8.50,60.1,116.2,0.1,,2.…
3 Algeria,2381.740,39.208,16.5,5361,30.5,24.6,0.29,,9.43,317.20,16.5,100.8,0.1…
4 American Samoa,0.200,0.055,275.0,,12.7,,,,,,,,,,,,,,,,,,,
5 Andorra,0.470,0.079,168.1,,13.8,9.5,1.67,,23.14,,94.0,80.7,,,5.4,,,,,,,,,
6 Angola,1246.700,21.472,17.2,5783,57.5,44.8,0.63,13.81,7.74,117.00,19.1,61.9,…
7 Antigua and Barbuda,0.440,0.090,204.5,13342,75.4,16.6,,,14.67,0.18,63.4,127.…
8 Argentina,2736.690,41.446,15.1,14715,8.5,16.9,1.46,,31.76,105.65,59.9,162.5,…
9 Armenia,28.470,2.977,104.6,3505,37,13.9,1.25,16.78,7.85,49.10,46.3,112.4,0.2…
10 Aruba,0.180,0.103,572.2,,57.9,10.4,,,,,78.9,134.9,,,13.0,10.3,8.4,11.3,75.3,…
# ℹ 207 more rows
# ℹ abbreviated name:
# ¹`Country,LandArea,Population,Density,GDP,Rural,CO2,PumpPrice,Military,Health,ArmedForces,Internet,Cell,HIV,Hunger,Diabetes,BirthRate,DeathRate,ElderlyPop,LifeExpectancy,FemaleLabor,Unemployment,EnergyUse,Electricity,Developed`
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 <- read_tsv("/cloud/project/data/minn_stp_weather.csv")
minn# A tibble: 1,403 × 1
`Description: Monthly weather data for Minneapolis-St. Paul, Minnesota`
<chr>
1 for 1/1900-12/2014.
2 Variables:
3 MonthY (Month of the year 1-12)
4 MonthS (Month of the Series 1-1380)
5 Year
6 LowTemp
7 HighTemp
8 WarmestMin (Warmest daily low temp)
9 ColdestHigh (Coldest daily high temp)
10 AveMin
# ℹ 1,393 more rows
Did you look at the data file before trying?
Now try the white_nonhisp_death_rates_from_1999_to_2013.txt data:
death_rates <- read_tsv("/cloud/project/data/white_nonhisp_death_rates_from_1999_to_2013.txt", col_names = TRUE)
death_rates# 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_tsv("/cloud/project/data/deaton.txt")
deaton# A tibble: 10 × 1
`age death_rate_1989 death_rate_2013 change`
<chr>
1 45 262.3 260.7 …
2 46 292.9 289.8 …
3 47 305.9 323.5 …
4 48 337.2 342.9 …
5 49 359.0 384.5 …
6 50 376.7 422.2 …
7 51 429.0 466.1 …
8 52 444.8 481.2 …
9 53 545.1 526.7 …
10 54 555.3 572.7 …
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_csv2("/cloud/project/data/pga2004.csv")
pga2004# A tibble: 209 × 1
`Aaron Baddeley,23,288,53.1,58.2,1.767,50.9,123,27,632878,23440`
<chr>
1 Adam Scott,24,295.4,57.7,65.6,1.757,59.3,7,16,3724984,232812
2 Alex Cejka,34,285.8,64.2,63.8,1.795,50.7,54,24,1313484,54729
3 Andre Stolz,34,297.9,59,63,1.787,47.7,101,20,808373,40419
4 Arjun Atwal,31,289.4,60.5,62.5,1.766,43.5,146,30,486053,16202
5 Arron Oberholser,29,284.6,68.8,67,1.78,50.9,52,23,1355433,58932
6 Bart Bryant,42,282.1,74.2,68.9,1.777,40.4,80,23,962167,41833
7 Ben Crane,28,283.8,64.4,64.2,1.74,53.8,75,27,1036958,38406
8 Ben Curtis,27,282.1,64.3,63.4,1.809,42.2,141,20,500818,25041
9 Bernhard Langer,47,282.2,62.6,65.3,1.777,47.7,83,15,943589,62906
10 Billy Andrade,40,283.5,59.7,64.4,1.773,50.5,124,31,631143,20359
# ℹ 199 more rows
Lastly, read in the noise.txt data:
noise <- read_tsv("/cloud/project/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