-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeRouteID.R
executable file
·59 lines (45 loc) · 1.63 KB
/
makeRouteID.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
56
57
58
59
# Make the route ID for the model
makeID <- function(x){
paste(x[-length(x)], x[-1])
}
# Need to define each reach as A1 - A2, not by receiver at A2
tars = ls(pattern = "routeSac")
new_vects <- sapply(tars, function(x)
apply(get(x), 2, makeID), simplify = FALSE)
levs <- unique(unlist(new_vects))
tars <- ls(pattern = "yolo201[2|3]_vector")
new_vects <- sapply(tars, function(x)
makeID(get(x)), simplify = FALSE)
levs <- unique(c(levs, unlist(new_vects)))
levs
# Reaches
reachSac12 <- apply(routeSac12, 2, function(x){
match(makeID(x), levs)
})
reachSac13 <- apply(routeSac13, 2, function(x){
match(makeID(x), levs)
})
reachYolo12 <- match(makeID(yolo2012_vector), levs)
reachYolo13 <- match(makeID(yolo2013_vector), levs)
# Reach length
sac2012_RouteA_reaches <- c(sac2012_RouteA_reaches[1:5],
"39" = 0,
sac2012_RouteA_reaches[6:8])
sac2012_RouteC_reaches <- c(sac2012_RouteC_reaches[1:5],
"39" = 0,
sac2012_RouteC_reaches[6:8])
sac2013_RouteB_reaches <- c(sac2013_RouteB_reaches[1:11],
"39" = 0,
sac2013_RouteB_reaches[12:14])
sac2013_RouteC_reaches <- c(sac2013_RouteC_reaches[1:11],
"39" = 0,
sac2013_RouteC_reaches[12:14])
tars <- ls(pattern = "_reaches")
reach_length <- lapply(tars, function(x){
# browser()
tmp <- get(x)
idx <- match(makeID(names(tmp)), levs)
structure(tmp[-1], names = makeID(names(tmp)))
})
reach_length <- do.call(c, reach_length)
reach_length <- reach_length[levs]