Skip to content
Prev 303221 / 398503 Next

named character question

On Aug 12, 2012, at 8:33 PM, Erin Hodgess wrote:

            
> ttt <- "200 W Rosamond St, Houston, TX 77076, USA"

 > sub("^.+,.+,\\s[[:alpha:]]*\\s([[:digit:]]{5}).+", "\\1", ttt)
[1] "77076"

You will need to determine if all you addresses have two commas before  
the two letter state designation. You may not need as specific a  
pattern as this. An alternate pattern.

 > sub("^.+\\s[[:alpha:]]{2}\\s([[:digit:]]{5}).+", "\\1", ttt)
[1] "77076"