I'm not sure you need grep:
> all %in% some
[1] TRUE FALSE TRUE FALSE FALSE TRUE
On Thu, May 19, 2016 at 7:58 PM, MacQueen, Don wrote:
> Start with:
>
> > all <- c("ants","birds","cats","dogs","elks","fox")
> > all[grep('ants|cats|fox',all)]
> [1] "ants" "cats" "fox"
>
> Then construct the f
Start with:
> all <- c("ants","birds","cats","dogs","elks","fox")
> all[grep('ants|cats|fox',all)]
[1] "ants" "cats" "fox"
Then construct the first arg to grep:
> some <- c("ants","cats","fox")
> all[ grep( paste(some,collapse='|') , all)]
[1] "ants" "cats" "fox"
--
Don MacQueen
Lawrence Li
> On May 19, 2016, at 4:09 PM, Steven Yen wrote:
>
> What is a good way to grep multiple strings (say in a vector)? In the
> following, I grep ants, cats, and fox separately and concatenate them,
> is there a way to grep the trio in one action? Thanks.
>
> all<-c("ants","birds","cats","dogs",
I use my own functions multiGrep and multiGrepl:
multiGrep = function(patterns, x, ..., sort = TRUE, invert = FALSE)
{
if (invert)
{
out = multiIntersect(lapply(patterns, grep, x, ..., invert = TRUE))
} else
out = unique(unlist(lapply(patterns, grep, x, ..., invert = FALSE)));
if (
No matter how expert you are at writing regular expressions,
it is important to list which sorts of strings you want matched
and which you do not want matched. Saying you want to match
"age" but not "age2" leads to lots of possibilities. Saying how
you want to categorize each string in a vector o
> On May 3, 2016, at 11:16 PM, Jeff Newmiller wrote:
>
> Yes, but the answer is likely to depend on the actual patterns of strings in
> your real data, so the sooner you go find a book or tutorial on regular
> expressions the better. This is decidedly not R specific and there are
> already l
You asked this question yesterday, and received responses on this same
response. Is there a reason this is reposted?
-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Steven Yen
Sent: Wednesday, May 04, 2016 1:46 AM
To: r-help
Subject: [R] Grep command
> x <- c("abc","def","rst","xyz","age","age2")
> grep("^age$", x)
[1] 5
> grep("^age2$", x)
[1] 6
>
>
-Oprindelig meddelelse-
Fra: R-help [mailto:r-help-boun...@r-project.org] På vegne af Steven Yen
Sendt: 4. maj 2016 07:46
Til: r-help
Emne: [R] Grep command
Dear all
In the grep command
Yes, but the answer is likely to depend on the actual patterns of strings in
your real data, so the sooner you go find a book or tutorial on regular
expressions the better. This is decidedly not R specific and there are already
lots of resources out there.
Given the example you provide, the p
Hi Steven,
grep uses regex... so you can use this:
-grep("age$",x): it says: match "a", then "g", then "e" and stop. The "$"
menas until here and no more.
> grep("age$",x)
[1] 5
2016-05-04 1:02 GMT-05:00 Jim Lemon :
> Hi Steven,
> If this is just a one-off, you could do this:
>
> grepl("age",
Hi Steven,
If this is just a one-off, you could do this:
grepl("age",x) & nchar(x)<4
returning a logical vector containing TRUE for "age" but not "age2"
Jim
On Wed, May 4, 2016 at 3:45 PM, Steven Yen wrote:
> Dear all
> In the grep command below, is there a way to identify only "age" and
> no
On 05/03/2016 06:05 AM, Jeff Newmiller wrote:
Isn't that just an inefficient way to do
"age" == x
Yep, it's an inefficient way to do which(x == "age").
H.
?
--
Hervé Pagès
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fa
Isn't that just an inefficient way to do
"age" == x
?
--
Sent from my phone. Please excuse my brevity.
On May 3, 2016 3:57:05 AM PDT, Ivan Calandra
wrote:
>What about?
>
>grep("^age$", x)
>
>Ivan
>
>--
>Ivan Calandra, PhD
>Scientific Mediator
>University of Reims Champagne-Ardenne
>GEGENAA -
Oh, and regarding the moderator approval, I guess it's because you're a
new user to the list.
Ivan
--
Ivan Calandra, PhD
Scientific Mediator
University of Reims Champagne-Ardenne
GEGENAA - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
ivan.calan...@univ-reims.
What about?
grep("^age$", x)
Ivan
--
Ivan Calandra, PhD
Scientific Mediator
University of Reims Champagne-Ardenne
GEGENAA - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
ivan.calan...@univ-reims.fr
--
https://www.researchgate.net/profile/Ivan_Calandra
https://
15 matches
Mail list logo