If you split the strings using strsplit: s <- strsplit(Names," *[()]") # remove space * if trailing space OK
Then the two results are: sapply(s,"[",-2) sapply(s,"[",2) --- Date: Mon, 13 Oct 2003 16:30:37 +0200 From: Martin Olivier <[EMAIL PROTECTED]> Subject: [R] help with gsub and grep functions Hi all, Let Names a vector of chatacters. For example, > Names [1] "g 604 be-0 -p1 (602 matches)" "g 606 Phli-0 -p2 (517 matches)" [3] "g 608 alu-0 (659 matches)" I try to use gsub or grep functions for two problems : 1. First, I would like to delete all the characters between parentheses. [1] "g 604 be-0 -p1" "g 606 be-0 -p2" [3] "g 608 be-0 -p3" 2. And, I would like to extract the characters between parentheses [1] "602 matches" "517 matches" [3] "659 matches" Any idea? _______________________________________________ No banners. No pop-ups. No kidding. Introducing My Way - http://www.myway.com ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help