[R] regular exprs
David Winsemius
dwinsemius at comcast.net
Sun Nov 7 16:36:41 CET 2010
On Nov 7, 2010, at 10:30 AM, David Winsemius wrote:
>
> On Nov 7, 2010, at 10:15 AM, Dimitris Rizopoulos wrote:
>
>> Dear All,
>>
>> I would appreciate any help with the following: given the vector 'x'
>>
>> x <- c("Ass1", "Ass.s1", "Ass2", "Ass.s2")
>>
>> I would like to pick up the positions where the character string
>> contains "Ass" but does not contain "Ass.s", so for 'x' that would
>> be positions 1 and 3.
>
> > x[ grepl("Ass", x) & !grepl("Ass\\.s", x) ]
> [1] "Ass1" "Ass2"
Or if locations were needed the:
> setdiff( grep("Ass", x) , grep("Ass\\.s", x) )
[1] 1 3
>
> HTH;
> --
> David
>
>>
>> I guess this could be programmed around grep() using a suitable
>> regular expression, but I haven't managed to succeed.
>>
>> Thanks in advance.
>>
>> Best,
>> Dimitris
>>
>> --
>> Dimitris Rizopoulos
>> Assistant Professor
>
> David Winsemius, MD
> West Hartford, CT
>
> ______________________________________________
> R-help at 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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list