Skip to content

Commit

Permalink
up revised usps function
Browse files Browse the repository at this point in the history
  • Loading branch information
bfifield committed Jun 8, 2017
1 parent 10f9c40 commit 204877a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
S3method(summary,fastLink)
export(aggregateEM)
export(calcMoversPriors)
export(cleanAddressUSPS)
export(clusterMatch)
export(dedupeMatches)
export(emlinkMARmov)
Expand Down
37 changes: 37 additions & 0 deletions R/cleanAddressUSPS.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' cleanAddressUSPS
#'
#' Apply USPS address standardization to address field.
#'
#' @usage cleanAddressUSPS(address.field)
#' @param address.field A vector containing address information to be cleaned.
#'
#' @return \code{cleanAddressUSPS()} returns a cleaned version of \code{address.field}.
#'
#' @author Ted Enamorado <[email protected]> and Ben Fifield <[email protected]>
#' @examples dfA$streetname <- cleanAddressUSPS(dfA$streetname)
#' @export
cleanAddressUSPS <- function(address.field){

## Standardization
address.field <- ifelse(grepl(" avenue", address.field),
gsub(" avenue", " ave", address.field),
ifelse(grepl(" avn", address.field),
gsub(" avn", " ave", address.field),
gsub(" av ", " ave", address.field)))
address.field <- gsub(" boulevard", " blvd", address.field)
address.field <- gsub(" circle", " cir", address.field)
address.field <- gsub(" court", " ct", address.field)
address.field <- gsub(" drive", " dr", address.field)
address.field <- gsub(" junction", " jct", address.field)
address.field <- gsub(" place", " pl", address.field)
address.field <- gsub(" road", " rd", address.field)
address.field <- gsub(" route", " rte", address.field)
address.field <- gsub(" square", " sq", address.field)
address.field <- gsub(" street", " st", address.field)
address.field <- gsub(" apartment", " apt", address.field)
address.field <- gsub(" building", " bldg", address.field)

return(trimws(address.field))

}

24 changes: 24 additions & 0 deletions man/cleanAddressUSPS.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 204877a

Please sign in to comment.