[R] help with gsub and grep functions
Gabor Grothendieck
ggrothendieck at myway.com
Tue Oct 14 01:54:01 CEST 2003
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 <martinol at ensam.inra.fr>
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
More information about the R-help
mailing list