-
Notifications
You must be signed in to change notification settings - Fork 0
/
02_halte.R
52 lines (41 loc) · 1.15 KB
/
02_halte.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
library(tidyverse)
# read data
df_tj <- readRDS("data/tj_detail.rds")
# checking
df_tj %>%
filter(name == "2B") %>%
.$route_info %>%
.[[1]] %>%
.$stops %>%
View()
df_tj$route_info[[1]]
map(df_tj$route_info, "id")
map(df_tj$route_info, "name")
map(df_tj$route_info, "stops")
map(df_tj$route_info, "tracks")
# create halte data
df_tj <- df_tj %>%
as_tibble() %>%
mutate(halte_detail = map(df_tj$route_info, "stops"))
df_halte <- df_tj %>%
select(schedule_id = scheduleId,
transport_id = transportId,
validity,
name, long_name = longName, color,
halte_detail) %>%
unnest() %>%
rename(halte_id = id,
halte_name = name1,
area_name = areaName,
direction_name = directionName)
df_halte_final <- df_halte %>%
group_by(halte_id, halte_name, lat, lng) %>%
summarise(route_cnt = n_distinct(schedule_id),
schedule_id = list(unique(schedule_id))) %>%
ungroup() %>%
rename(latitude = lat, longitude = lng)
# finalization
transjakarta <- df_halte_final %>%
select(everything(), schedule_id, corridor_cnt = route_cnt)
# save data
saveRDS(transjakarta, "data/tj_halte.rds")