Code
library(tidyverse)
library(here)
library(readxl)
::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE) knitr
Daniel Manning
December 28, 2022
Today’s challenge is to
read in a dataset, and
describe the dataset using both words and any supporting information (e.g., tables, etc)
Read in one (or more) of the following data sets, using the correct R package and command.
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
.
I changed my working directory to the location of the csv file within the local folder on my desktop. I then used read.csv() to store the railroad dataset within my railroad variable. Based on the output when calling the variable railroads, the state column and county columns consist of characters while the total_employee column consists of integers.
# 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
Add any comments or documentation as needed. More challenging data sets may require additional code chunks and documentation.
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).
First I used the head() function to determine that the dataset has three variables, including state (with a two letter code), county (with a three letter code), and total_employees (representing the total railroad employees per county). This dataset was likely gathered by survey. Then I used dim() to show that their are 2930 rows representing the total number of counties with railroad employees. Next I stored the columns into individual variables for ease of use later on. I used the n_distinct() and distinct() functions to show that there were 53 unique entries in the state column and to ouput these values. I then calculated summary statistics for the total employees. Next I used the with() and t_apply() function to output the number of railroad employees in each state and store them in a new variable. Lastly, I calculated summary statistics of this new by_states variable.
# 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
[1] 2930 3
[1] 53
# A tibble: 53 × 1
state
<chr>
1 AE
2 AK
3 AL
4 AP
5 AR
6 AZ
7 CA
8 CO
9 CT
10 DC
# … with 43 more rows
[1] 87.17816
[1] 21
[1] 1
[1] 8207
[1] 283.6359
[1] 80449.32
[1] 58
[1] 4819.472
[1] 3379
[1] 1
[1] 19839
[1] 4781.829
[1] 22865885
[1] 4175
---
title: "Challenge 1"
author: "Daniel Manning"
description: "Reading in data and creating a post"
date: "12/28/2022"
format:
html:
toc: true
code-fold: true
code-copy: true
code-tools: true
categories:
- challenge_1
---
```{r}
#| label: setup
#| warning: false
#| message: false
library(tidyverse)
library(here)
library(readxl)
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`.
I changed my working directory to the location of the csv file within the local folder on my desktop. I then used read.csv() to store the railroad dataset within my railroad variable. Based on the output when calling the variable railroads, the state column and county columns consist of characters while the total_employee column consists of integers.
```{r}
railroad <- here("posts","_data","railroad_2012_clean_county.csv")%>%
read_csv()
railroad
```
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).
First I used the head() function to determine that the dataset has three variables, including state (with a two letter code), county (with a three letter code), and total_employees (representing the total railroad employees per county). This dataset was likely gathered by survey. Then I used dim() to show that their are 2930 rows representing the total number of counties with railroad employees. Next I stored the columns into individual variables for ease of use later on. I used the n_distinct() and distinct() functions to show that there were 53 unique entries in the state column and to ouput these values. I then calculated summary statistics for the total employees. Next I used the with() and t_apply() function to output the number of railroad employees in each state and store them in a new variable. Lastly, I calculated summary statistics of this new by_states variable.
```{r}
#| label: summary
head(railroad)
dim(railroad)
state <- railroad$state
county <- railroad$county
total_employees <- railroad$total_employees
railroad %>%
select(state) %>%
n_distinct(.)
railroad %>%
select(state) %>%
distinct()
mean(total_employees)
median(total_employees)
min(total_employees)
max(total_employees)
sd(total_employees)
var(total_employees)
IQR(total_employees)
by_state <- railroad %>% with(tapply(total_employees,state,FUN=sum))
mean(by_state)
median(by_state)
min(by_state)
max(by_state)
sd(by_state)
var(by_state)
IQR(by_state)
```