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
  • 178,638
  • 15
  • 253
  • 268
Math Expert
  • 161
  • 2
  • 3
  • 9

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
  • 29,327
  • 7
  • 77
  • 89
A. Blizzard
  • 241
  • 2
  • 13