Challenge 1 Solutions

challenge_1
Tenzin Latoe
railroads
Reading in data and creating a post
Author

Tenzin Latoe

Published

June 20, 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

  • railroad_2012_clean_county.csv ⭐
Code
railroad <- read_csv("_data/railroad_2012_clean_county.csv")
Code
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
# ℹ 2,920 more rows

Describe the data

The data consists of 2930 rows and 3 columns, which represent State, county, and total employees.

Code
#Preview: railroad
head(railroad)
# A tibble: 6 × 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

Head function used to preview the first 5 rows of the dataframe

Code
colnames(railroad)
[1] "state"           "county"          "total_employees"
Code
#Filter Massachusetts from railroad
filter(railroad, `state` == "MA")
# A tibble: 12 × 3
   state county     total_employees
   <chr> <chr>                <dbl>
 1 MA    BARNSTABLE              44
 2 MA    BERKSHIRE               50
 3 MA    BRISTOL                232
 4 MA    ESSEX                  314
 5 MA    FRANKLIN               113
 6 MA    HAMPDEN                202
 7 MA    HAMPSHIRE               68
 8 MA    MIDDLESEX              673
 9 MA    NORFOLK                386
10 MA    PLYMOUTH               429
11 MA    SUFFOLK                558
12 MA    WORCESTER              310

To specifically at MA, we can can filter the data by searching specific states. I selected MA from the current railroad dataset.