-
Notifications
You must be signed in to change notification settings - Fork 2
/
clean.R
38 lines (37 loc) · 2.23 KB
/
clean.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
in_file <- "addresses_raw.txt"
out_file <- "addresses_cleaned.txt"
ftext <- read.csv(file=in_file,header=FALSE,sep="~")
#print(class(ftext))
colnames(ftext) = c("Raw_Address")
ftext[,1] <- toupper(ftext[,1])
ftext[] <- lapply(ftext, function(x) gsub("\\s+", " ", x))
ftext[] <- lapply(ftext, function(x) gsub(" ST ", " STREET ", x))
ftext[] <- lapply(ftext, function(x) gsub(" LOOP ", " LOOP ", x))
ftext[] <- lapply(ftext, function(x) gsub(" RISE ", " RISE ", x))
ftext[] <- lapply(ftext, function(x) gsub(" ARC "," ARCADE ", x))
ftext[] <- lapply(ftext, function(x) gsub(" ESP "," ESPLANADE ", x))
ftext[] <- lapply(ftext, function(x) gsub(" CV "," COVE ", x))
ftext[] <- lapply(ftext, function(x) gsub(" CRES "," CRESCENT ", x))
ftext[] <- lapply(ftext, function(x) gsub(" CR "," CRESCENT ", x))
ftext[] <- lapply(ftext, function(x) gsub(" RD "," ROAD ", x))
ftext[] <- lapply(ftext, function(x) gsub(" AVE "," AVENUE ", x))
ftext[] <- lapply(ftext, function(x) gsub(" PL "," PLACE ", x))
ftext[] <- lapply(ftext, function(x) gsub(" CRT "," COURT ", x))
ftext[] <- lapply(ftext, function(x) gsub(" CT "," COURT ", x))
ftext[] <- lapply(ftext, function(x) gsub(" DR "," DRIVE ", x))
ftext[] <- lapply(ftext, function(x) gsub(" TCE "," TERRACE ", x))
ftext[] <- lapply(ftext, function(x) gsub(" PDE "," PARADE ", x))
ftext[] <- lapply(ftext, function(x) gsub("CCT "," CIRCUIT ", x))
ftext[] <- lapply(ftext, function(x) gsub(" CRST "," CREST ", x))
ftext[] <- lapply(ftext, function(x) gsub(" LA "," LANE ", x))
ftext[] <- lapply(ftext, function(x) gsub(" WAY "," WAY ", x))
ftext[] <- lapply(ftext, function(x) gsub(" GDN "," GARDENS ", x))
ftext[] <- lapply(ftext, function(x) gsub(" GDNS "," GARDENS ", x))
ftext[] <- lapply(ftext, function(x) gsub(" CL "," CLOSE ", x))
ftext[] <- lapply(ftext, function(x) gsub(" HWY "," HIGHWAY ", x))
ftext[] <- lapply(ftext, function(x) gsub(" CCS "," CIRCUS ", x))
ftext[] <- lapply(ftext, function(x) gsub(" CCL "," CIRCLE ", x))
ftext[] <- lapply(ftext, function(x) gsub(" BVD "," BOULEVARD ", x))
ftext[] <- lapply(ftext, function(x) gsub(" BLVD "," BOULEVARD ", x))
#write.csv(x=ftext,file=out_file,append=FALSE,quote=FALSE,col.names=NA,row.names=FALSE)
write.table(x=ftext,file=out_file,append=FALSE,row.names=FALSE, quote=FALSE)