DACSS 601: Data Science Fundamentals - FALL 2022
  • Fall 2022 Posts
  • Contributors
  • DACSS

Challenge 1 Kristin Abijaoude

  • Course information
    • Overview
    • Instructional Team
    • Course Schedule
  • Weekly materials
    • Fall 2022 posts
    • final posts

On this page

  • Challenge Overview
  • Read in the Data
  • Describe the data

Challenge 1 Kristin Abijaoude

  • Show All Code
  • Hide All Code

  • View Source
challenge_1
railroads
kristin_abijaoude
Author

Kristin Abijaoude

Published

September 15, 2022

Code
library(tidyverse)
library(dplyr)

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
railroads<- read_csv("_data/railroad_2012_clean_county.csv")
railroads
# 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

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
summary(railroads)
    state              county          total_employees  
 Length:2930        Length:2930        Min.   :   1.00  
 Class :character   Class :character   1st Qu.:   7.00  
 Mode  :character   Mode  :character   Median :  21.00  
                                       Mean   :  87.18  
                                       3rd Qu.:  65.00  
                                       Max.   :8207.00  

In total, we have 2930 entries in this dataset, with 2930 counties across the US accounted for. Some counties have a minimum of 1 railroad employee, while Cook County, IL has the most with 8207 railroad employees.

Here are the first 6 rows of the dataset. In total, there are 2930 rows and 3 columns: state, county, and total employees.

Code
head(railroads)
# 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
Code
dim(railroads)
[1] 2930    3
Code
colnames(railroads)
[1] "state"           "county"          "total_employees"

Let’s narrow it down to Massachusetts, where we are now. There are 12 counties in Massachusetts, with Barnstable County with the least amount of railroad employees with 44 of them, while Middlesex County has the most with 673 railroad employees.

Code
filter(railroads, 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
Code
filter(railroads, `total_employees` > 1000)
# A tibble: 27 × 3
   state county         total_employees
   <chr> <chr>                    <dbl>
 1 CA    LOS ANGELES               2545
 2 CA    RIVERSIDE                 1567
 3 CA    SAN BERNARDINO            2888
 4 CT    NEW HAVEN                 1561
 5 DE    NEW CASTLE                1275
 6 FL    DUVAL                     3073
 7 IL    COOK                      8207
 8 IL    WILL                      1784
 9 IN    LAKE                      1999
10 KS    JOHNSON                   1286
# … with 17 more rows

There are 27 counties with more than 1000 total railroad employees, while there are 488 counties with fewer than 5 (yes, you read that correctly) railroad employees.

Code
filter(railroads, `total_employees` < 5)
# A tibble: 488 × 3
   state county               total_employees
   <chr> <chr>                          <dbl>
 1 AE    APO                                2
 2 AK    FAIRBANKS NORTH STAR               2
 3 AK    JUNEAU                             3
 4 AK    MATANUSKA-SUSITNA                  2
 5 AK    SITKA                              1
 6 AL    BARBOUR                            1
 7 AL    FAYETTE                            3
 8 AL    HENRY                              1
 9 AL    PERRY                              4
10 AP    APO                                1
# … with 478 more rows
Code
filter(railroads, `total_employees` > 1000 & `state` == "CA")
# A tibble: 3 × 3
  state county         total_employees
  <chr> <chr>                    <dbl>
1 CA    LOS ANGELES               2545
2 CA    RIVERSIDE                 1567
3 CA    SAN BERNARDINO            2888

When I used the filter code to only show California, the nation’s most populous state, it’s unsurprising that there would be a lot of railroad employees.

Source Code
---
title: "Challenge 1 Kristin Abijaoude"
author: "Kristin Abijaoude"
desription: "Reading in data and creating a post"
date: "09/15/2022"
format:
  html:
    toc: true
    code-fold: true
    code-copy: true
    code-tools: true
categories:
  - challenge_1
  - railroads
  - kristin_abijaoude
---

```{r}
#| label: setup
#| warning: false
#| message: false

library(tidyverse)
library(dplyr)

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`.

```{r}
#| label: read
railroads<- read_csv("_data/railroad_2012_clean_county.csv")
railroads
```

## 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).

```{r}
#| label: Summary
summary(railroads)
```

In total, we have 2930 entries in this dataset, with 2930 counties across the US accounted for. Some counties have a minimum of 1 railroad employee, while Cook County, IL has the most with 8207 railroad employees.

Here are the first 6 rows of the dataset. In total, there are 2930 rows and 3 columns: state, county, and total employees.

```{r}
head(railroads)
```

```{r}
dim(railroads)
```

```{r}
colnames(railroads)
```

Let's narrow it down to Massachusetts, where we are now. There are 12 counties in Massachusetts, with Barnstable County with the least amount of railroad employees with 44 of them, while Middlesex County has the most with 673 railroad employees.

```{r}
filter(railroads, state == "MA")
```

```{r}
filter(railroads, `total_employees` > 1000)
```

There are 27 counties with more than 1000 total railroad employees, while there are 488 counties with fewer than 5 (yes, you read that correctly) railroad employees.

```{r}
filter(railroads, `total_employees` < 5)
```

```{r}
filter(railroads, `total_employees` > 1000 & `state` == "CA")
```

When I used the filter code to only show California, the nation's most populous state, it's unsurprising that there would be a lot of railroad employees.