true
true
true
Reading in data and creating a post
Author

Linda Humphrey

Published

February 22, 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

The data is about Total railroad employment by state and county

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

The data contains variables such as,calender year 2012, States, Counties and number of railroad employees in each of the states in accordance to the counties.

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
library(readr)
dataset <- read_csv("~/Desktop/Dacss601_spring2023/posts/_data/railroad_2012_clean_county.csv") 
View(dataset)
#Filter dataset of total_employees >= 2
filter(dataset, total_employees >= 2)
# A tibble: 2,785 × 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    SKAGWAY MUNICIPALITY              88
 7 AL    AUTAUGA                          102
 8 AL    BALDWIN                          143
 9 AL    BIBB                              25
10 AL    BLOUNT                           154
# … with 2,775 more rows
Code
#Arrange dataset of state & total_employees
dataset <- read_csv("~/Desktop/Dacss601_spring2023/posts/_data/railroad_2012_clean_county.csv")
arrange(dataset, desc(total_employees))
# A tibble: 2,930 × 3
   state county           total_employees
   <chr> <chr>                      <dbl>
 1 IL    COOK                        8207
 2 TX    TARRANT                     4235
 3 NE    DOUGLAS                     3797
 4 NY    SUFFOLK                     3685
 5 VA    INDEPENDENT CITY            3249
 6 FL    DUVAL                       3073
 7 CA    SAN BERNARDINO              2888
 8 CA    LOS ANGELES                 2545
 9 TX    HARRIS                      2535
10 NE    LINCOLN                     2289
# … with 2,920 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
dataset <- read_csv("~/Desktop/Dacss601_spring2023/posts/_data/railroad_2012_clean_county.csv")

dataset <- read_csv("~/Desktop/Dacss601_spring2023/posts/_data/railroad_2012_clean_county.csv")

print(is.data.frame(dataset))
[1] TRUE
Code
print(ncol(dataset))
[1] 3
Code
print(nrow(dataset))
[1] 2930
Code
# Get the max total_employees from dataset

total_employees <- max(dataset$total_employees)
print(total_employees)
[1] 8207
Code
# Get details of state with min total_employees from dataset

dataset <- read_csv("~/Desktop/Dacss601_spring2023/posts/_data/railroad_2012_clean_county.csv")


total_employees <- min(dataset$total_employees)
print(total_employees)
[1] 1
Code
# Get details of state with Mean total_employees from dataset

dataset <- read_csv("~/Desktop/Dacss601_spring2023/posts/_data/railroad_2012_clean_county.csv")


total_employees.mean <- mean(dataset$total_employees)
print(total_employees.mean)
[1] 87.17816