Challenge 1 Instructions

challenge_1
railroads
faostat
wildbirds
Reading in data and creating a post
Author

Sean Conway

Published

May 30, 2023

Code
library(tidyverse)

knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)

Challenge Overview

Today’s challenge is to

  1. read in a dataset, and

  2. describe the dataset using both words and any supporting information (e.g., tables, etc)

Read in the Data

Read in one (or more) of the following data sets, using the correct R package and command.

  • railroad_2012_clean_county.csv ⭐
  • birds.csv ⭐⭐
  • FAOstat*.csv ⭐⭐
  • wild_bird_data.xlsx ⭐⭐⭐
  • StateCounty2012.xls ⭐⭐⭐⭐

Find the _data folder, located inside the posts folder. Then you can read in the data, using either one of the readr standard tidy read commands, or a specialized package such as readxl.

Code
list.files("_data")
 [1] "AB_NYC_2019.csv"                                                                                 
 [2] "abc_poll_2021.csv"                                                                               
 [3] "ActiveDuty_MaritalStatus.xls"                                                                    
 [4] "animal_weight.csv"                                                                               
 [5] "australian_marriage_law_postal_survey_2017_-_response_final.xls"                                 
 [6] "australian_marriage_tidy.csv"                                                                    
 [7] "birds.csv"                                                                                       
 [8] "cereal.csv"                                                                                      
 [9] "cwc.csv"                                                                                         
[10] "Data_Extract_From_World_Development_Indicators.xlsx"                                             
[11] "Data_Extract_FromWorld Development Indicators.xlsx"                                              
[12] "debt_in_trillions.xlsx"                                                                          
[13] "eggs_tidy.csv"                                                                                   
[14] "FAOSTAT_cattle_dairy.csv"                                                                        
[15] "FAOSTAT_country_groups.csv"                                                                      
[16] "FAOSTAT_egg_chicken.csv"                                                                         
[17] "FAOSTAT_livestock.csv"                                                                           
[18] "FedFundsRate.csv"                                                                                
[19] "FRBNY-SCE-Public-Microdata-Complete-13-16.xlsx"                                                  
[20] "hotel_bookings.csv"                                                                              
[21] "organiceggpoultry.xls"                                                                           
[22] "poultry_tidy.csv"                                                                                
[23] "poultry_tidy.RData"                                                                              
[24] "poultry_tidy.xlsx"                                                                               
[25] "Public_School_Characteristics_2017-18.csv"                                                       
[26] "railroad_2012_clean_county.csv"                                                                  
[27] "sce-labor-chart-data-public.xlsx"                                                                
[28] "snl_actors.csv"                                                                                  
[29] "snl_casts.csv"                                                                                   
[30] "snl_seasons.csv"                                                                                 
[31] "starwars1.RData"                                                                                 
[32] "StateCounty2012.xls"                                                                             
[33] "test_objs.RData"                                                                                 
[34] "Total_cost_for_top_15_pathogens_2018.xlsx"                                                       
[35] "USA Households by Total Money Income, Race, and Hispanic Origin of Householder 1967 to 2019.xlsx"
[36] "wild_bird_data.xlsx"                                                                             
Code
railroad_csv <- read_csv("_data/railroad_2012_clean_county.csv") 
birds_from_csv <- read_csv("_data/birds.csv")
railroad_csv 
# A tibble: 2,930 × 3
   state county               total_employees
   <chr> <chr>                          <dbl>
 1 AE    APO                                2
 2 AK    ANCHORAGE                          7
 3 AK    FAIRBANKS NORTH STAR               2
 4 AK    JUNEAU                             3
 5 AK    MATANUSKA-SUSITNA                  2
 6 AK    SITKA                              1
 7 AK    SKAGWAY MUNICIPALITY              88
 8 AL    AUTAUGA                          102
 9 AL    BALDWIN                          143
10 AL    BARBOUR                            1
# ℹ 2,920 more rows
Code
birds_from_csv
# A tibble: 30,977 × 14
   `Domain Code` Domain     `Area Code` Area  `Element Code` Element `Item Code`
   <chr>         <chr>            <dbl> <chr>          <dbl> <chr>         <dbl>
 1 QA            Live Anim…           2 Afgh…           5112 Stocks         1057
 2 QA            Live Anim…           2 Afgh…           5112 Stocks         1057
 3 QA            Live Anim…           2 Afgh…           5112 Stocks         1057
 4 QA            Live Anim…           2 Afgh…           5112 Stocks         1057
 5 QA            Live Anim…           2 Afgh…           5112 Stocks         1057
 6 QA            Live Anim…           2 Afgh…           5112 Stocks         1057
 7 QA            Live Anim…           2 Afgh…           5112 Stocks         1057
 8 QA            Live Anim…           2 Afgh…           5112 Stocks         1057
 9 QA            Live Anim…           2 Afgh…           5112 Stocks         1057
10 QA            Live Anim…           2 Afgh…           5112 Stocks         1057
# ℹ 30,967 more rows
# ℹ 7 more variables: Item <chr>, `Year Code` <dbl>, Year <dbl>, Unit <chr>,
#   Value <dbl>, Flag <chr>, `Flag Description` <chr>

Add any comments or documentation as needed. More challenging data sets may require additional code chunks and documentation.

Describe the data

Using a combination of words and results of R commands, can you provide a high level description of the data? Describe as efficiently as possible where/how the data was (likely) gathered, indicate the cases and variables (both the interpretation and any details you deem useful to the reader to fully understand your chosen data).

Code
glimpse(railroad_csv) 
Rows: 2,930
Columns: 3
$ state           <chr> "AE", "AK", "AK", "AK", "AK", "AK", "AK", "AL", "AL", …
$ county          <chr> "APO", "ANCHORAGE", "FAIRBANKS NORTH STAR", "JUNEAU", …
$ total_employees <dbl> 2, 7, 2, 3, 2, 1, 88, 102, 143, 1, 25, 154, 13, 29, 45…
Code
spec(railroad_csv)
cols(
  state = col_character(),
  county = col_character(),
  total_employees = col_double()
)
Code
typeof(railroad_csv$state)
[1] "character"
Code
typeof(railroad_csv$county)
[1] "character"
Code
typeof(railroad_csv$total_employees)
[1] "double"

In the railroad_2012_clean_county dataset we have 2930 rows and 3 columns(state, county and total_employees). With the data given in this dataset we can only know about the total number of employees in a county is and what state that county belongs to. And the types of the variables state, county and total_employees are character, character and double.

Code
glimpse(birds_from_csv) 
Rows: 30,977
Columns: 14
$ `Domain Code`      <chr> "QA", "QA", "QA", "QA", "QA", "QA", "QA", "QA", "QA…
$ Domain             <chr> "Live Animals", "Live Animals", "Live Animals", "Li…
$ `Area Code`        <dbl> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, …
$ Area               <chr> "Afghanistan", "Afghanistan", "Afghanistan", "Afgha…
$ `Element Code`     <dbl> 5112, 5112, 5112, 5112, 5112, 5112, 5112, 5112, 511…
$ Element            <chr> "Stocks", "Stocks", "Stocks", "Stocks", "Stocks", "…
$ `Item Code`        <dbl> 1057, 1057, 1057, 1057, 1057, 1057, 1057, 1057, 105…
$ Item               <chr> "Chickens", "Chickens", "Chickens", "Chickens", "Ch…
$ `Year Code`        <dbl> 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 196…
$ Year               <dbl> 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 196…
$ Unit               <chr> "1000 Head", "1000 Head", "1000 Head", "1000 Head",…
$ Value              <dbl> 4700, 4900, 5000, 5300, 5500, 5800, 6600, 6290, 630…
$ Flag               <chr> "F", "F", "F", "F", "F", "F", "F", NA, "F", "F", "F…
$ `Flag Description` <chr> "FAO estimate", "FAO estimate", "FAO estimate", "FA…
Code
spec(birds_from_csv) # To check data types of columns 
cols(
  `Domain Code` = col_character(),
  Domain = col_character(),
  `Area Code` = col_double(),
  Area = col_character(),
  `Element Code` = col_double(),
  Element = col_character(),
  `Item Code` = col_double(),
  Item = col_character(),
  `Year Code` = col_double(),
  Year = col_double(),
  Unit = col_character(),
  Value = col_double(),
  Flag = col_character(),
  `Flag Description` = col_character()
)
Code
typeof(birds_from_csv$'Domain Code') 
[1] "character"
Code
typeof(birds_from_csv$Domain) 
[1] "character"
Code
typeof(birds_from_csv$'Area Code') 
[1] "double"
Code
typeof(birds_from_csv$Area) 
[1] "character"
Code
typeof(birds_from_csv$'Element Code') 
[1] "double"
Code
typeof(birds_from_csv$Element) 
[1] "character"
Code
typeof(birds_from_csv$'Item Code') 
[1] "double"
Code
typeof(birds_from_csv$Item) 
[1] "character"
Code
typeof(birds_from_csv$'Year Code') 
[1] "double"
Code
typeof(birds_from_csv$Year) 
[1] "double"
Code
typeof(birds_from_csv$Unit) 
[1] "character"
Code
typeof(birds_from_csv$Value) 
[1] "double"
Code
typeof(birds_from_csv$Flag) 
[1] "character"
Code
typeof(birds_from_csv$'Flag Description')
[1] "character"

In the birds dataset we have 30977 rows and 14 columns(Domain, Area, Element, Year etc). In this dataset , the data is recorded form 1961 - 2018 , about the region(Area) and different types of birds(like chicken and duck) in that region and information about birds like count(Unit), Value and flag. This information is liekly gathered to know the inforamtion of number of birds in each area for every year from 1961 to 2018 or it may also be the information of buying live animals(birds) every year from each area.