0

Raw Data:

550 LEE DR BATON ROUGE, LA 70802 (30.399995, -91.15418)
2810 SCENIC HW BATON ROUGE, LA 70805 (30.473461, -91.168378)
11201 MEAD RD BATON ROUGE, LA
550 LEE DR BATON ROUGE, LA 70802 (30.399995, -91.15418)
2810 SCENIC HW BATON ROUGE, LA 70805 (30.473461, -91.168378)
11201 MEAD RD BATON ROUGE, LA

For R, I am trying to set up a code that will give me the following geolocation results (remember I don't want the NA records gone but to just leave it blank):

(30.399995, -91.15418)
(30.473461, -91.168378)
NA    
(30.399995, -91.15418)    
(30.473461, -91.168378)    
NA

I tried:

ag <- data.frame(sub(".*\\((.*)\\).*", "\\1", 
geolocation$test.Geolocation, perl=TRUE))
ag

but to no avail. I appreciate the help.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Math Expert
  • 181
  • 2
  • 3
  • 11

1 Answers1

0

Try:

fun <- function(x){
  res <- regmatches(x, gregexpr("\\(.*\\)", x))[[1]]
  ifelse(length(res) == 0, NA_character_, res)
}

unlist(sapply(geolocation$test.Geolocation, fun))
Axeman
  • 32,068
  • 8
  • 81
  • 94
Arktik
  • 263
  • 3
  • 13