Instantly share code, notes, and snippets.

@andrewbtran /Chunk 6
Last active Jul 14, 2018

Embed
What would you like to do?
---
title: "Chunk 6"
author: "Andrew"
date: "7/23/2018"
output:
html_document:
theme: united
highlight: espresso
---
```{r loading, warning=F, message=F, echo=F}
# load packages
library(tidyverse)
# Loading the Boston city payroll
payroll <- read_csv("data/bostonpayroll2013.csv")
```
```{r cleaning_data, warning=F, echo=F}
colnames(payroll) <- make.names(colnames(payroll))
payroll$REGULAR <- gsub("\\$", "", payroll$REGULAR)
payroll$REGULAR <- gsub(",", "", payroll$REGULAR)
payroll$REGULAR <- as.numeric(payroll$REGULAR)
payroll$RETRO <- gsub("\\$", "", payroll$RETRO)
payroll$RETRO <- gsub(",", "", payroll$RETRO)
payroll$RETRO <- as.numeric(payroll$RETRO)
payroll$OTHER <- gsub("\\$", "", payroll$OTHER)
payroll$OTHER <- gsub(",", "", payroll$OTHER)
payroll$OTHER <- as.numeric(payroll$OTHER)
payroll$OTHER <- gsub("\\$", "", payroll$OTHER)
payroll$OTHER <- gsub(",", "", payroll$OTHER)
payroll$OTHER <- as.numeric(payroll$OTHER)
payroll$OVERTIME <- gsub("\\$", "", payroll$OVERTIME)
payroll$OVERTIME <- gsub(",", "", payroll$OVERTIME)
payroll$OVERTIME <- as.numeric(payroll$OVERTIME)
payroll$INJURED <- gsub("\\$", "", payroll$INJURED)
payroll$INJURED <- gsub(",", "", payroll$INJURED)
payroll$INJURED <- as.numeric(payroll$INJURED)
payroll$DETAIL <- gsub("\\$", "", payroll$DETAIL)
payroll$DETAIL <- gsub(",", "", payroll$DETAIL)
payroll$DETAIL <- as.numeric(payroll$DETAIL)
payroll$QUINN <- gsub("\\$", "", payroll$QUINN)
payroll$QUINN <- gsub(",", "", payroll$QUINN)
payroll$QUINN <- as.numeric(payroll$QUINN)
payroll$TOTAL.EARNINGS <- gsub("\\$", "", payroll$TOTAL.EARNINGS)
payroll$TOTAL.EARNINGS <- gsub(",", "", payroll$TOTAL.EARNINGS)
payroll$TOTAL.EARNINGS <- as.numeric(payroll$TOTAL.EARNINGS)
```
```{r analysis, warning=F, message=F}
top5 <- payroll %>%
group_by(DEPARTMENT) %>%
summarize(Average.Earnings=mean(TOTAL.EARNINGS, na.rm=T)) %>%
arrange(desc(Average.Earnings)) %>%
head(5)
```
```{r table, warning=F, echo=F}
library(knitr)
kable(top5)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment