Thanks guys. I've pulled my O'Reilly book and will begin reviewing it.
Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry
Indiana University School of Medicine
15032 Hunter Court, Westfield, IN 46074
(317) 490-5129 Work, & M
2009 9:28 AM
To: William Dunlap; r-help@r-project.org
Subject: Re: [R] help with regular expressions in R
Well, I guess I'm not quite there yet. What I gave earlier was a
simplified example, and did not accurately reflect the complexity of the
task.
Well, I guess I'm not quite there yet. What I gave earlier was a simplified
example, and did not accurately reflect the complexity of the task.
This is my real world example. As you can see, what I need to do is delete
an arbitrary number of characters, including brackets and parens enclosing
them
Mark,
Try this:
> myCharVec
[1] "[the rain in spain]" "(the rain in spain)"
> gsub("\\[.*\\]", "", myCharVec)
[1] """(the rain in spain)"
You need two backslashes to "escape" the square brackets. The regular
expression "\\[.\\]" translates to "a [ followed by 0 or more insta
How about this:
> myCharVec <- c("[the rain in spain]", "(the rain in spain)")
> gsub('\\[.*\\]', '', myCharVec)
[1] """(the rain in spain)"
>
you had "*." when you should have ".*"
On Thu, Aug 20, 2009 at 11:30 AM, Mark Kimpel wrote:
> I'm having trouble achieving the resul
5 matches
Mail list logo