-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeocoding.R
More file actions
189 lines (143 loc) · 4.07 KB
/
Geocoding.R
File metadata and controls
189 lines (143 loc) · 4.07 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
install.packages("mapproj")
install.packages("ggmap")
install.packages("DeducerSpatial")
install.packages("zipcode")
install.packages("rgeos")
install.packages("DeducerSpatial")
install.packages("geosphere")
install.packages("maps")
install.packages("ggplot2")
install.packages("plyr")
install.packages("ggmap")
install.packages ("maptools")
install.packages ("xlsx")
install.packages ("choroplethr")
install.packages ("choroplethrMaps")
install.packages ("mapproj")
install.packages ("ggplot2")
install.packages ("choroplethr")
library(ggplot2)
library(rgdal)
library(scales)
library(ggmap)
library(dplyr)
library(Cairo)
library(choroplethr)
library(choroplethrMaps)
library(mapproj)
library(ggplot2)
library(ggmap)
library(geosphere)
library(rgeos)
library(maps)
library(zipcode)
data(zipcode)
library(ggmap)
mapdist('48116', '48109', mode = 'driving')
distQueryCheck()
#the basics
#loading the file
complezip <- read.csv(file="c:/users/owner/documents/comple_zip.csv")
#shape of the data
head(complezip)
#dimensions rows vs columns
dim(complezip)
#headers
names(complezip)
#information about the file
str(complezip)
#quick summary
summary(complezip)
#look at specific columns
complezip_only <- complezip[,3:3]
complezip_only
#create new table
write.table(complezip_only, "complezip_only.csv", row.names=FALSE, sep=",")
centerszip <- read.csv(file="c:/users/owner/documents/centers.csv")
complezip$Zip_Code
centerszip$Zip_Code
from <- "complezip$Zip_Code"[c(1:1064)]
to <- "centerszip$Zip_Code"[c(1)]
from <- complezip$Zip_Code
to <- centerszip$Zip_Code
mapdist(from, to, mode="driving")
from <- "complezip$Zip_Code"
to <- "centerszip$Zip_Code"
mapdist(from, to, mode="driving")
str(complezip$Zip_Code)
str(centerszip$Zip_Code)
data <- read.table("comple_zip.csv", header=TRUE, sep=",", skip=7,
stringsAsFactors=FALSE)
read.table("comple_zip.csv", header = TRUE, sep = ",", row.names = 1)
mydata=read.csv("comple_zip.csv", header=FALSE, sep=",", as.is=FALSE, skip=7,
stringsAsFactors=FALSE)
mydata = read.csv("comple_zip.csv")
mydata
str(mydata)
mydata [,3]
str(complezip)
library(zipcode)
data(zipcode)
fm<- read.csv("zip_codes.csv", header = TRUE, sep = ",")
data(zipcode)
fm$zip<- clean.zipcodes(fm$Zip_Code)
fm<- merge(fm, zipcode, by.x='zip', by.y='zip')
fm
write.csv(fm,file="ZIP.csv")
--------------------------------------------------------------------------------
#selecting the file to work with
myzip<- read.csv("ZIP.csv")
myzip
#shape of the data
head(myzip)
#dimensions rows vs columns
dim(myzip)
#headers
names(myzip)
#information about the file
str(myzip)
#quick summary
summary(myzip)
summary(myzip$zip)
table(myzip$zip)
--------------------------------------------------------------------------
#This is working!
myzip<- read.csv("ZIP.csv")
myzip
library(ggmap)
options(max.print=1000000)
test <- as.character(myzip$zip)
test
from=test
to = "48109"
mapdist(from, to, mode="driving")
distQueryCheck()
--------------------------------------------------------------------------------
api_key <- "AIzaSyAPYrB1NtXDfUjqE2OS7ENJfYY7fq40OFU"
--------------------------------------------------------------------------------
# Complete code & saving output to csv
myzip<- read.csv("ZIP.csv")
str(myzip)
library(ggmap)
options(max.print=1000000)
a <- as.character(myzip$zip)
str(a)
from=a
to = "48109"
mapdist(from, to, mode="driving")
m=mapdist(from, to, mode="driving")
dat1 <- data.frame(m)
write.csv(dat1, file = "test3.csv")
distQueryCheck()
--------------------------------------------------------------------------------
#geocoding centers
library(zipcode)
data(zipcode)
library(zipcode)
data(zipcode)
fm<- read.csv("centers.csv", header = TRUE, sep = ",")
fm$zip<- clean.zipcodes(fm$Zip_Code)
a <- merge(fm, zipcode, by.x='zip', by.y='zip')
a
write.csv(a, file = "centers.csv")
--------------------------------------------------------------------------------