Created
March 9, 2016 20:48
-
-
Save stedy/b619ffd468d0a639fd7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(dplyr) | |
| raw_data <- read.csv("https://s3.amazonaws.com/pix-media/Data+for+TreefortBnB+Puzzle.csv") %>% | |
| mutate(City = tolower(City)) | |
| simpleCap <- function(x) { | |
| s <- strsplit(x, " ")[[1]] | |
| paste(toupper(substring(s, 1, 1)), substring(s, 2), | |
| sep = "", collapse = " ") | |
| } | |
| city_statecount_data <- | |
| raw_data %>% | |
| group_by(City, State) %>% | |
| do(data.frame(cs_count=length(.$Unique.id))) %>% | |
| subset(cs_count >= 5) %>% | |
| select(City, State) | |
| summary_data <- | |
| raw_data %>% | |
| merge(city_statecount_data) %>% | |
| group_by(City, State) %>% | |
| do(data.frame(medianprice = median(.$X..Price))) %>% | |
| rowwise() %>% | |
| mutate(City = simpleCap(City)) %>% | |
| arrange(desc(medianprice)) | |
| write.csv(summary_data[1:100, ], "TreefortBNB_summary.csv", row.names=F) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment