generated from KSUDS/p3_spatial
-
Notifications
You must be signed in to change notification settings - Fork 1
/
eda.R
55 lines (46 loc) · 2.04 KB
/
eda.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
51
52
53
54
55
install.packages("sf")
install.packages("jsonlite")
library(tidyverse)
library(sf)
library(jsonlite)
#%%
json_to_tibble <- function(x){
if(is.na(x)) return(x)
parse_json(x) %>%
enframe() %>%
unnest(value)
}
dat <- read_csv("SafeGraph - Patterns and Core Data - Chipotle - July 2021/Core Places and Patterns Data/chipotle_core_poi_and_patterns.csv")
dat %>%
slice(1:5) %>% #by rows
pull (related_same_day_brand) #to print out col
datNest <- dat %>%
slice(1:25) %>% # for the example
mutate(
visitor_country_of_origin = map(visitor_country_of_origin, ~json_to_tibble(.x)),
bucketed_dwell_times = map(bucketed_dwell_times, ~json_to_tibble(.x)),
related_same_day_brand = map(related_same_day_brand, ~json_to_tibble(.x)),
related_same_month_brand = map(related_same_month_brand, ~json_to_tibble(.x)),
popularity_by_hour = map(popularity_by_hour, ~json_to_tibble(.x)),
popularity_by_day = map(popularity_by_day, ~json_to_tibble(.x)),
device_type = map(device_type, ~json_to_tibble(.x)),
visitor_home_cbgs = map(visitor_home_cbgs, ~json_to_tibble(.x)),
visitor_home_aggregation = map(visitor_home_aggregation, ~json_to_tibble(.x)),
visitor_daytime_cbgs = map(visitor_daytime_cbgs, ~json_to_tibble(.x))
)
datNest %>%
slice(1:5) %>%
select(placekey, location_name, longitude, latitude, city, region, device_type) %>%
unnest(device_type) %>%
filter(!is.na(name)) %>% #! means you want to drop all na in names
pivot_wider(names_from = name, values_from = value)
#melt into an icle, narrow the dateset
#gather is down to melt
#pivot longer, how long do you want this data to be
datNest %>%
slice(1:5) %>%
select(placekey, location_name, longitude, latitude, city, region, device_type, popularity_by_day) %>%
unnest(popularity_by_day) %>%
filter(!is.na(name)) %>% #! means you want to drop all na in names
pivot_wider(names_from = name, values_from = value) %>%
unnest(device_type)