Skip to content

Instantly share code, notes, and snippets.

@stedy
Created March 9, 2016 20:48
Show Gist options
  • Select an option

  • Save stedy/b619ffd468d0a639fd7e to your computer and use it in GitHub Desktop.

Select an option

Save stedy/b619ffd468d0a639fd7e to your computer and use it in GitHub Desktop.
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