-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.R
executable file
·55 lines (43 loc) · 1.55 KB
/
global.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
library(dplyr)
library(shiny)
library(FNN)
library(sp)
options(shiny.port = 2410)
# allzips <- readRDS("data/superzip.rds")
allzips <- accidents <- read.csv("data/berlin_bike_accidents_neukoelln_2002_2015.csv")
coordinates(accidents) <- c("X_SOLDNER", "Y_SOLDNER")
proj4string(accidents) <- CRS("+init=epsg:3068")
CRS.new <- CRS("+init=epsg:4326")
accidents.coords <- spTransform(accidents, CRS.new)
accidentsSp <- SpatialPoints(accidents.coords)
cc <- coordinates(accidentsSp) %>% data.frame
xing <- read.csv("data/re_vms_detailnetz.csv")
names(xing) <- c("long", "lat", "xid")
r <- get.knnx(
xing %>% select(long, lat) %>% data.matrix,
allzips %>% select(long, lat) %>% data.matrix,
1
)
allzips$lat <- cc$Y_SOLDNER
allzips$long <- cc$X_SOLDNER
allzips <- allzips %>% mutate(
B1URSACHE1 = B1URSACHE1 %>% gsub("\"", "", .),
latitude = jitter(lat),
longitude = jitter(long),
college = B2ALTER * 100,
severity = BETEILIGTE + 2*LEICHTVERL + 5*SCHWERVERL + 10*GETOETETE,
date = as.Date(DATUM),
total_injured = LEICHTVERL + SCHWERVERL + GETOETETE,
month=substr(allzips$DATUM,6,7),
xing = xing[r$nn.index,"xid"],
xingdist = r$nn.dist[,1],
bike = (B1VERKEHRS == "Radfahrer" & B1URS1 > 0) | (B2VERKEHRS == "Radfahrer" & B2URS1 > 0),
car = (B1VERKEHRS != "Radfahrer" & B1URS1 > 0) | (B2VERKEHRS != "Radfahrer" & B2URS1 > 0)
)
nicons <- function(ic, n) {
i <- icon(ic) %>% as.character
res <- paste(replicate(n, i), collapse = "")
return(HTML(res))
}
#allzips <- allzips %>% filter(xing == 5655 & xingdist < 0.0005)
cleantable <- allzips