-
Notifications
You must be signed in to change notification settings - Fork 0
/
geocode_data.R
50 lines (40 loc) · 1.2 KB
/
geocode_data.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
data_refact <- read.csv("data/data_refact.csv")
library(ggmap)
loc <- data_refact %>%
select(campground, city, state) %>%
distinct() %>%
mutate(full_loc = paste(campground, city, state, sep = ", "))
#good
loc_geocode <- loc %>%
mutate_geocode(full_loc)
#get missing
loc_geocode2 <- loc_geocode %>%
filter(is.na(lon)) %>%
select(-lon, -lat) %>%
mutate_geocode(full_loc)
#get more missing
loc_geocode3 <- loc_geocode2 %>%
filter(is.na(lon)) %>%
select(-lon, -lat) %>%
mutate_geocode(full_loc)
#get more missing
loc_geocode4 <- loc_geocode3 %>%
filter(is.na(lon)) %>%
select(-lon, -lat) %>%
mutate_geocode(full_loc)
#get last missing
loc_geocode5 <- loc_geocode4 %>%
filter(is.na(lon)) %>%
mutate(lat = 43.15817,
lon = -122.133642)
#combine
all_loc <- bind_rows(loc_geocode, loc_geocode2,
loc_geocode3, loc_geocode4,
loc_geocode5) %>%
filter(!is.na(lon)) %>%
select(full_loc, lon, lat)
data_combined <- data_refact %>%
mutate(full_loc = paste(campground, city, state, sep = ", ")) %>%
left_join(all_loc)
write.csv(data_combined, "data/data_geocoded.csv",
row.names = FALSE)