Code
library(tidyverse)
::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE) knitr
Amer Abuhasan
August 16, 2022
Today’s challenge is to
Read in one (or more) of the following data sets, available in the posts/_data
folder, using the correct R package and command.
# 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 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).
Conduct some exploratory data analysis, using dplyr commands such as group_by()
, select()
, filter()
, and summarise()
. Find the central tendency (mean, median, mode) and dispersion (standard deviation, mix/max/quantile) for different subgroups within the data set.
# A tibble: 53 × 2
state n
<chr> <int>
1 AE 1
2 AK 6
3 AL 67
4 AP 1
5 AR 72
6 AZ 15
7 CA 55
8 CO 57
9 CT 8
10 DC 1
# … with 43 more rows
# A tibble: 53 × 2
state E
<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
# A tibble: 1,709 × 2
county E
<chr> <dbl>
1 ABBEVILLE 124
2 ACADIA 13
3 ACCOMACK 4
4 ADA 81
5 ADAIR 29
6 ADAMS 878
7 ADDISON 8
8 AIKEN 193
9 AITKIN 19
10 ALACHUA 22
# … with 1,699 more rows
# 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
# A tibble: 1,939 × 3
state county total_employees
<chr> <chr> <dbl>
1 AK SKAGWAY MUNICIPALITY 88
2 AL AUTAUGA 102
3 AL BALDWIN 143
4 AL BIBB 25
5 AL BLOUNT 154
6 AL BULLOCK 13
7 AL BUTLER 29
8 AL CALHOUN 45
9 AL CHAMBERS 13
10 AL CHILTON 72
# … with 1,929 more rows
Be sure to explain why you choose a specific group. Comment on the interpretation of any interesting differences between groups that you uncover. This section can be integrated with the exploratory data analysis, just be sure it is included.
#explain The data i used above was able to group by different columns # the first code The first code was used to find the amount labeled(N) to see how many times a state was mentioned in the columns
#the second code The second code was using the state and seeing how many employees were in that state
#the third code The third code allowed to go into depth on the employee count and sum the number of employees in each county.
#the Fifth Code The fifth code explains total employees over the number of 10
---
title: "Challenge 2 solutions"
author: "Amer Abuhasan"
desription: "Data wrangling: using group() and summarise()"
date: "08/16/2022"
format:
html:
toc: true
code-fold: true
code-copy: true
code-tools: true
categories:
- challenge_2
- railroads
- faostat
- hotel_bookings
---
```{r}
#| label: setup
#| warning: false
#| message: false
library(tidyverse)
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```
## Challenge Overview
Today's challenge is to
1) read in a data set, and describe the data using both words and any supporting information (e.g., tables, etc)
2) provide summary statistics for different interesting groups within the data, and interpret those statistics
## Read in the Data
Read in one (or more) of the following data sets, available in the `posts/_data` folder, using the correct R package and command.
- railroad\*.csv or StateCounty2012.xls ⭐
- FAOstat\*.csv or birds.csv ⭐⭐⭐
- hotel_bookings.csv ⭐⭐⭐⭐
```{r}
railroad <- read_csv("_data/railroad_2012_clean_county.csv")
railroad
```
Add any comments or documentation as needed. More challenging data 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).
```{r}
#| label: summary
#The data provided is the Countys in each state and the ammount of Employees who work for the railroads. Each county has a certain amount of counties and we will be grouping them together to show states and counties together to add up the employees
```
## Provide Grouped Summary Statistics
Conduct some exploratory data analysis, using dplyr commands such as `group_by()`, `select()`, `filter()`, and `summarise()`. Find the central tendency (mean, median, mode) and dispersion (standard deviation, mix/max/quantile) for different subgroups within the data set.
```{r}
library(dplyr)
railroad%>%
group_by(state) %>%
summarise(n = n())
railroad%>%
group_by(state)%>%
summarise(E= sum(total_employees))
railroad%>%
group_by(county)%>%
summarise(E= sum(total_employees))
library(dplyr)
filter(railroad, 'total_employees' >=100)
railroad%>%
filter(total_employees>10)
```
### Explain and Interpret
Be sure to explain why you choose a specific group. Comment on the interpretation of any interesting differences between groups that you uncover. This section can be integrated with the exploratory data analysis, just be sure it is included.
#explain
The data i used above was able to group by different columns
# the first code
The first code was used to find the amount labeled(N) to see how many times a state was mentioned in the columns
#the second code
The second code was using the state and seeing how many employees were in that state
#the third code
The third code allowed to go into depth on the employee count and sum the number of employees in each county.
#the Fifth Code
The fifth code explains total employees over the number of 10