Skip to content
Prev 303255 / 398503 Next

named character question

HI,

One more method to extract the code:
add1<-"200 W Rosamond St, Houston, TX 77076, USA"
?sub(".*\\s.*\\s.*\\s.*\\s.*\\s.*\\s([[:digit:]]{5}).*","\\1",add1)
#[1] "77076"

#or,
?sub(".*\\s+([[:digit:]]{5}).*","\\1",ttt)
#[1] "77076"


A.K.





----- Original Message -----
From: Erin Hodgess <erinm.hodgess at gmail.com>
To: R help <r-help at stat.math.ethz.ch>
Cc: 
Sent: Sunday, August 12, 2012 11:33 PM
Subject: [R]  named character question

Dear R People:

Here is a goofy question:

I want to extract the zip code from an address and here is my work so far:
? ? ? ? ? ? ? ? ? results.formatted_address
"200 W Rosamond St, Houston, TX 77076, USA"
<NA> <NA> <NA> <NA> <NA>
? NA?  NA?  NA?  NA?  NA
Named chr "200 W Rosamond St, Houston, TX 77076, USA"
- attr(*, "names")= chr "results.formatted_address"
What am I not seeing, please?

Thanks,
Erin