Challenge 1 Instructions

challenge_1
Author

Meredith Rolfe

Published

August 15, 2022

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.xlsx ⭐⭐⭐⭐

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
railroad <- read_csv("_data/railroad_2012_clean_county.csv")
railroad
# 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
# … with 2,920 more rows
# ℹ Use `print(n = ...)` to see more rows

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
spec(railroad)
cols(
  state = col_character(),
  county = col_character(),
  total_employees = col_double()
)
Code
railroad %>%
  filter(state == "AK")
# A tibble: 6 × 3
  state county               total_employees
  <chr> <chr>                          <dbl>
1 AK    ANCHORAGE                          7
2 AK    FAIRBANKS NORTH STAR               2
3 AK    JUNEAU                             3
4 AK    MATANUSKA-SUSITNA                  2
5 AK    SITKA                              1
6 AK    SKAGWAY MUNICIPALITY              88
Code
railroad %>%
  group_by(state) %>%
  summarise(total_employees2 = sum(total_employees))
# A tibble: 53 × 2
   state total_employees2
   <chr>            <dbl>
 1 AE                   2
 2 AK                 103
 3 AL                4257
 4 AP                   1
 5 AR                3871
 6 AZ                3153
 7 CA               13137
 8 CO                3650
 9 CT                2592
10 DC                 279
# … with 43 more rows
# ℹ Use `print(n = ...)` to see more rows

When I used the spec() function, it returned the variable types of the columns. We know that state is type col_character(), county is type col_character() and total_employees is type col_double(). When I filtered through just the state of AK it returns the list of the total employees for each county in that state. I created a pipe that groups all the states together an than is summarized by the total amount of employees in each state. This pipe is useful because I now know how many total employees are in each state. This data was likely gathered in 2012 from the most used railroad stations in the USA. This dataset is also long in the sense that the column length is much greater than the amount of columns present.