Created
January 31, 2018 17:37
-
-
Save EmilHvitfeldt/9bf6d6e085254719e9db5aaa19bc5bc5 to your computer and use it in GitHub Desktop.
data points in states
This file contains 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(maps) | |
library(tidyverse) | |
# Having the data.csv file in the same working directory | |
data <- read_csv("data.csv") | |
data_states <- data %>% | |
mutate(state = map.where('state', Longitude, Latitude)) %>% | |
# Removes point not in a state | |
filter(!is.na(state)) %>% | |
# Some states are subdivided, this mutate call collapes them together | |
mutate(state = if_else(str_detect(state, ":"), | |
str_extract(state, ".+?(?=:)"), | |
state)) | |
data_states %>% | |
count(state) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment