You are treating add1 as a vector of characters. If you want the zipcode and you know what positions it is within the string use
substr(add1[1], 32, 36) If you don't know, you could use (but it will get any 5 digit number): regmatches(add1, regexpr("[[:digit:]]{5}", add1)) ---------------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Erin Hodgess > Sent: Sunday, August 12, 2012 10:34 PM > To: R help > 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: > > > add1 > results.formatted_address > "200 W Rosamond St, Houston, TX 77076, USA" > > add1[1][32:36] > <NA> <NA> <NA> <NA> <NA> > NA NA NA NA NA > > str(add1) > Named chr "200 W Rosamond St, Houston, TX 77076, USA" > - attr(*, "names")= chr "results.formatted_address" > > > > What am I not seeing, please? > > Thanks, > Erin > > > -- > Erin Hodgess > Associate Professor > Department of Computer and Mathematical Sciences > University of Houston - Downtown > mailto: erinm.hodg...@gmail.com > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.