Instantly share code, notes, and snippets.

@andrewbtran /Chunk 7
Last active Jul 14, 2018

Embed
What would you like to do?
---
title: "Chunk 7"
author: "Andrew"
date: "3/10/2018"
output:
html_document:
toc: true
toc_float: true
---
# Boston employee pay in 2014
```{r loading, warning=F, message=F, echo=F}
# load packages
library(tidyverse)
# Loading the Boston city payroll
payroll <- read_csv("data/bostonpayroll2013.csv")
colnames(payroll) <- make.names(colnames(payroll))
payroll_total <- select(payroll, NAME, TITLE, DEPARTMENT, TOTAL.EARNINGS)
```
```{r display_data, warning=F, message=F, echo=F}
library(DT)
datatable(payroll_total)
```
# Departments with the highest average pay
```{r cleaning_data, warning=F, echo=F}
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, echo=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