On 02-Mar-2014 20:12:57 Benno Pütz wrote: > Try > > as.numeric(sub(".*\\(","", sub('\\)','',aa))) > > You may also want to look at regexec/regmatches for a more general approach > ... > > On 02 Mar 2014, at 20:55, Doran, Harold <hdo...@air.org> wrote: > >> "1 (472)" "2 (445)" "3 (431)" "3 (431)" "5 (415)" "6 (405)" "7 (1) > > Benno Pütz
Another formulation, which breaks it into steps and may therefore be easier to adopt to similar but different cases, is aa0<-gsub("^[0-9]+ ","",aa) aa0 # [1] "(472)" "(445)" "(431)" "(431)" "(415)" "(405)" "(1)" as.numeric(gsub("[()]","",aa0)) # [1] 472 445 431 431 415 405 1 Ted. ------------------------------------------------- E-Mail: (Ted Harding) <ted.hard...@wlandres.net> Date: 02-Mar-2014 Time: 20:57:07 This message was sent by XFMail ______________________________________________ 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.