Data Import

library(tidyverse)
Crime_2015 <- read_csv("http://jsuleiman.com/datasets/Crime_2015.csv")
CollegeScorecard <-
  read_csv("http://jsuleiman.com/datasets/CollegeScorecard.csv")

Define Cornelia’s Requirements

Find median of Violent Crime excluding NA values

summarise(Crime_2015, median(ViolentCrime, na.rm = TRUE))
## # A tibble: 1 x 1
##   `median(ViolentCrime, na.rm = TRUE)`
##                                  <dbl>
## 1                                 334.

Find median of Midpoint Math SAT Score excluding NA value

summarise(CollegeScorecard, median(SATMTMID, na.rm = TRUE))
## # A tibble: 1 x 1
##   `median(SATMTMID, na.rm = TRUE)`
##                              <dbl>
## 1                              520

Combine datasets and filter by Cornelia’s requirements

Combine via left join CollegeScorecard and Crime_2015

Cornelia <- CollegeScorecard %>% left_join(Crime_2015, by=c("CITY" = "City", "STABBR" = "State"))

Filter for values meeting Cornelia’s criteria

Cornelia %>% filter(ViolentCrime < 334) %>% filter(SATMTMID > 520) %>% filter(AccredAgency == "Southern Association of Colleges and Schools Commission on Colleges") %>% select(INSTNM, CITY, ViolentCrime, SATMTMID,AccredAgency) %>% slice_max(
SATMTMID, n = 5)
## # A tibble: 5 x 5
##   INSTNM           CITY     ViolentCrime SATMTMID AccredAgency                  
##   <chr>            <chr>           <dbl>    <dbl> <chr>                         
## 1 University of V… Charlot…         165.      685 Southern Association of Colle…
## 2 Southern Method… Dallas           331.      660 Southern Association of Colle…
## 3 The University … Austin           288.      650 Southern Association of Colle…
## 4 University of G… Athens           326.      625 Southern Association of Colle…
## 5 Austin College   Sherman          327.      615 Southern Association of Colle…

Create output dataframe for Cornelia

Output <- (Cornelia %>% select(INSTNM, CITY, ViolentCrime, SATMTMID,AccredAgency)) %>% filter(ViolentCrime < 334) %>%  filter(SATMTMID > 520) %>% filter(AccredAgency == "Southern Association of Colleges and Schools Commission on Colleges")

Output <- aggregate(ViolentCrime ~ INSTNM+CITY+SATMTMID+AccredAgency, Output, mean)

Output <- Output %>% select(INSTNM, CITY, SATMTMID, ViolentCrime, AccredAgency) %>% arrange(desc(SATMTMID))

Output$row_num <- seq.int(nrow(Output))

Output <- Output %>% select(INSTNM, CITY, SATMTMID, ViolentCrime, AccredAgency, row_num) %>% arrange(desc(SATMTMID))

Create table for Cornelia

library(knitr) 
kable(Output, 
col.names = c('College Name', 'City', 'SAT Midpoint Math Score', 'Violent Crime Rate', 'Accreditation Agency', 'Count'), align = "cccccr", caption = "Cornelia's College Scorecard") 
Cornelia’s College Scorecard
College Name City SAT Midpoint Math Score Violent Crime Rate Accreditation Agency Count
University of Virginia-Main Campus Charlottesville 685 164.6 Southern Association of Colleges and Schools Commission on Colleges 1
Southern Methodist University Dallas 660 330.6 Southern Association of Colleges and Schools Commission on Colleges 2
The University of Texas at Austin Austin 650 287.7 Southern Association of Colleges and Schools Commission on Colleges 3
University of Georgia Athens 625 325.7 Southern Association of Colleges and Schools Commission on Colleges 4
Austin College Sherman 615 327.1 Southern Association of Colleges and Schools Commission on Colleges 5
Texas A & M University-College Station College Station 605 315.5 Southern Association of Colleges and Schools Commission on Colleges 6
University of North Carolina at Asheville Asheville 595 202.0 Southern Association of Colleges and Schools Commission on Colleges 7
Mercer University Macon 590 319.9 Southern Association of Colleges and Schools Commission on Colleges 8
James Madison University Harrisonburg 580 145.8 Southern Association of Colleges and Schools Commission on Colleges 9
Transylvania University Lexington 570 256.3 Southern Association of Colleges and Schools Commission on Colleges 10
University of Kentucky Lexington 565 256.3 Southern Association of Colleges and Schools Commission on Colleges 11
Dallas Baptist University Dallas 562 330.6 Southern Association of Colleges and Schools Commission on Colleges 12
Saint Edward’s University Austin 560 287.7 Southern Association of Colleges and Schools Commission on Colleges 13
Virginia Commonwealth University Richmond 550 236.5 Southern Association of Colleges and Schools Commission on Colleges 14
The University of Texas at Tyler Tyler 544 295.7 Southern Association of Colleges and Schools Commission on Colleges 15
Randolph College Lynchburg 535 180.4 Southern Association of Colleges and Schools Commission on Colleges 16
Concordia University-Texas Austin 525 287.7 Southern Association of Colleges and Schools Commission on Colleges 17
Hollins University Roanoke 525 213.9 Southern Association of Colleges and Schools Commission on Colleges 18