forked from msr-ds3/subway-flow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSingularTrainFlow_LatLong.R
27 lines (20 loc) · 1.08 KB
/
SingularTrainFlow_LatLong.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
library(dplyr)
#Reading in the information from stop_times.txt
setwd("~/subway-flow/gtfs_data")
stops <- read.table("stops.txt",header=TRUE,
sep=",",fill=TRUE,quote = "",row.names = NULL,
stringsAsFactors = FALSE)
setwd("~/subway-flow/")
flow <- read.table("SingularTrainFlow.csv",header=TRUE,
sep=",",fill=TRUE,quote = "",row.names = NULL,
stringsAsFactors = FALSE)
stops$stop_id = substr(stops$stop_id, 0, 3)
stops<- unique(subset(stops,select=c("stop_id","stop_lat","stop_lon")))
stops_flow <- inner_join(flow,stops)
#taking only the first lat long for each station
firstids <- stops_flow %>% group_by(station_id) %>% summarise(stop_lat=first(stop_lat),stop_lon=first(stop_lon))
stops_flow$stop_lat= NULL
stops_flow$stop_lon=NULL
stops_flow <- inner_join(stops_flow,firstids,by="station_id")
stops_flow <- subset(stops_flow,select=c("train","train_stop","station_id","station","time_travel","line_name","stop_lat","stop_lon"))
write.csv(stops_flow,"~/subway-flow/SingularTrainFlowLatLon.csv",quote=FALSE)