I'm looking for a more elegant solution for this:
phone_number <- function(x) {
x <- gsub("[\\() -]", "", x)
x <- gsub("^(.{3})(.{3})(.*)","\\1-\\2-\\3", x, perl = TRUE)
}
This would take data like this:
(123) 123-1234
123-123-1234
123 123-1234
And produce this:
123-123-1234
123-123-1234
123-123-1234