[R] grep
John Fox
j|ox @end|ng |rom mcm@@ter@c@
Mon Jul 11 05:21:23 CEST 2022
Dear Steven,
Beyond ?regex, the Wikipedia article on regular expressions
<https://en.wikipedia.org/wiki/Regular_expression> is quite helpful and
not too long.
I hope this helps,
John
On 2022-07-10 9:43 p.m., Steven T. Yen wrote:
> Thanks Jeff. It works. If there is a good reference I should read
> (besides ? grep) I's be glad to have it.
>
> On 7/11/2022 9:30 AM, Jeff Newmiller wrote:
>> grep( "^(z|x)\\.", jj, value = TRUE )
>>
>> or
>>
>> grep( r"(^(z|x)\.)", jj, value = TRUE )
>>
>>
>> On July 10, 2022 6:08:45 PM PDT, "Steven T. Yen" <styen using ntu.edu.tw>
>> wrote:
>>> Dear, Below, jj contains character strings starting with “z.” and
>>> “x.”. I want to grep all that contain either “z.” or “x.”. I had to
>>> grep “z.” and “x.” separately and then tack the result together. Is
>>> there a convenient grep option that would grep strings with either
>>> “z.” or “x.”. Thank you!
>>>
>>>> jj<-names(v$est); jj
>>> [1] "z.one" "z.liberal" "z.conserv" "z.dem" "z.rep"
>>> "z.realinc"
>>> [7] "x.one" "x.liberal" "x.conserv" "x.dem" "x.rep"
>>> "x.realinc"
>>> [13] "mu1_1" "mu2_1" "rho"
>>>> j1<-grep("z.",jj,value=TRUE); j1
>>> [1] "z.one" "z.liberal" "z.conserv" "z.dem" "z.rep" "z.realinc"
>>>> j2<-grep("x.",jj,value=TRUE); j2
>>> [1] "x.one" "x.liberal" "x.conserv" "x.dem" "x.rep" "x.realinc"
>>>> j<-c(j1,j2); j
>>> [1] "z.one" "z.liberal" "z.conserv" "z.dem" "z.rep"
>>> "z.realinc"
>>> [7] "x.one" "x.liberal" "x.conserv" "x.dem" "x.rep"
>>> "x.realinc"
>>>
>>> ______________________________________________
>>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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 using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
--
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: https://socialsciences.mcmaster.ca/jfox/
More information about the R-help
mailing list