Thank you Bert for the pointer.
So I guess the solution is:
grep("ConfoMap.+GuineaPigs", mydata, value=TRUE)
This is not the case here, but what if "GuineaPigs" comes before
"ConfoMap"?
Of course I could do two "grep()" calls, but if there a better
solution?
Ivan
--
Dr. Ivan Calandra
TraCEr, laboratory for Traceology and Controlled Experiments
MONREPOS Archaeological Research Centre and
Museum for Human Behavioural Evolution
Schloss Monrepos
56567 Neuwied, Germany
+49 (0) 2631 9772-243
https://www.researchgate.net/profile/Ivan_Calandra
On 19/08/2020 17:07, Bert Gunter wrote:> "&" is not a regex metacharacter.
> See ?regexp
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip
)
>
>
> On Wed, Aug 19, 2020 at 7:53 AM Ivan Calandra <calandra at rgzm.de
> <mailto:calandra at rgzm.de>> wrote:
>
> Dear useRs,
>
> I feel really stupid, but I cannot understand why "&"
doesn't work
> as I
> expect, while "|" does.
>
> I have the following vector:
> mydata <- c("SSFA-ConfoMap_GuineaPigs_NMPfilled.csv",
> "SSFA-ConfoMap_Lithics_NMPfilled.csv",?
> "SSFA-ConfoMap_Sheeps_NMPfilled.csv",
> "SSFA-Toothfrax_GuineaPigs.xlsx",
> "SSFA-Toothfrax_Lithics.xlsx",
"SSFA-Toothfrax_Sheeps.xlsx")
> and I want to find the values that include both "ConfoMap"
and
> "GuineaPigs".
>
> If I do:
> grep("ConfoMap&GuineaPigs", mydata, value=TRUE)
> it returns an empty vector, character(0).
>
> But if I do:
> grep("ConfoMap|GuineaPigs", mydata, value=TRUE)
> it returns all the elements that include either "ConfoMap" or
> "GuineaPigs", as I would expect.
>
> So what is wrong with my "&" construct? How can I return
the elements
> that include both parts?
>
> Thank you for your help!
> Ivan
>
> --
> Dr. Ivan Calandra
> TraCEr, laboratory for Traceology and Controlled Experiments
> MONREPOS Archaeological Research Centre and
> Museum for Human Behavioural Evolution
> Schloss Monrepos
> 56567 Neuwied, Germany
> +49 (0) 2631 9772-243
> https://www.researchgate.net/profile/Ivan_Calandra
>
> ______________________________________________
> R-help at r-project.org <mailto:R-help at 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.
>
Well... wouldn't it be:
rep("(ConfoMap.*GuineaPigs)|(GuineaPigs.*ConfoMap)", mydata,
value=TRUE)
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Wed, Aug 19, 2020 at 8:23 AM Ivan Calandra <calandra at rgzm.de> wrote:
> Thank you Bert for the pointer.
>
> So I guess the solution is:
> grep("ConfoMap.+GuineaPigs", mydata, value=TRUE)
>
> This is not the case here, but what if "GuineaPigs" comes before
> "ConfoMap"?
> Of course I could do two "grep()" calls, but if there a better
solution?
>
> Ivan
>
> --
> Dr. Ivan Calandra
> TraCEr, laboratory for Traceology and Controlled Experiments
> MONREPOS Archaeological Research Centre and
> Museum for Human Behavioural Evolution
> Schloss Monrepos
> 56567 Neuwied, Germany
> +49 (0) 2631 9772-243
> https://www.researchgate.net/profile/Ivan_Calandra
>
> On 19/08/2020 17:07, Bert Gunter wrote:
> > "&" is not a regex metacharacter.
> > See ?regexp
> >
> > Bert Gunter
> >
> > "The trouble with having an open mind is that people keep coming
along
> > and sticking things into it."
> > -- Opus (aka Berkeley Breathed in his "Bloom County" comic
strip )
> >
> >
> > On Wed, Aug 19, 2020 at 7:53 AM Ivan Calandra <calandra at rgzm.de
> > <mailto:calandra at rgzm.de>> wrote:
> >
> > Dear useRs,
> >
> > I feel really stupid, but I cannot understand why
"&" doesn't work
> > as I
> > expect, while "|" does.
> >
> > I have the following vector:
> > mydata <- c("SSFA-ConfoMap_GuineaPigs_NMPfilled.csv",
> > "SSFA-ConfoMap_Lithics_NMPfilled.csv",
> > "SSFA-ConfoMap_Sheeps_NMPfilled.csv",
> > "SSFA-Toothfrax_GuineaPigs.xlsx",
> > "SSFA-Toothfrax_Lithics.xlsx",
"SSFA-Toothfrax_Sheeps.xlsx")
> > and I want to find the values that include both
"ConfoMap" and
> > "GuineaPigs".
> >
> > If I do:
> > grep("ConfoMap&GuineaPigs", mydata, value=TRUE)
> > it returns an empty vector, character(0).
> >
> > But if I do:
> > grep("ConfoMap|GuineaPigs", mydata, value=TRUE)
> > it returns all the elements that include either
"ConfoMap" or
> > "GuineaPigs", as I would expect.
> >
> > So what is wrong with my "&" construct? How can I
return the elements
> > that include both parts?
> >
> > Thank you for your help!
> > Ivan
> >
> > --
> > Dr. Ivan Calandra
> > TraCEr, laboratory for Traceology and Controlled Experiments
> > MONREPOS Archaeological Research Centre and
> > Museum for Human Behavioural Evolution
> > Schloss Monrepos
> > 56567 Neuwied, Germany
> > +49 (0) 2631 9772-243
> > https://www.researchgate.net/profile/Ivan_Calandra
> >
> > ______________________________________________
> > R-help at r-project.org <mailto:R-help at 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 at 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.
>
[[alternative HTML version deleted]]
Indeed! I was just hoping that there would be a shorter way... intersect() is a nice alternative too. Maybe I can make it work with pipes so that I don't have to repeat "mydata" but that's another story. Thank you for the help! Ivan -- Dr. Ivan Calandra TraCEr, laboratory for Traceology and Controlled Experiments MONREPOS Archaeological Research Centre and Museum for Human Behavioural Evolution Schloss Monrepos 56567 Neuwied, Germany +49 (0) 2631 9772-243 https://www.researchgate.net/profile/Ivan_Calandra On 19/08/2020 17:31, Bert Gunter wrote:> Well... wouldn't it be: > > rep("(ConfoMap.*GuineaPigs)|(GuineaPigs.*ConfoMap)", mydata, value=TRUE) > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Wed, Aug 19, 2020 at 8:23 AM Ivan Calandra <calandra at rgzm.de > <mailto:calandra at rgzm.de>> wrote: > > Thank you Bert for the pointer. > > So I guess the solution is: > grep("ConfoMap.+GuineaPigs", mydata, value=TRUE) > > This is not the case here, but what if "GuineaPigs" comes before > "ConfoMap"? > Of course I could do two "grep()" calls, but if there a better > solution? > > Ivan > > -- > Dr. Ivan Calandra > TraCEr, laboratory for Traceology and Controlled Experiments > MONREPOS Archaeological Research Centre and > Museum for Human Behavioural Evolution > Schloss Monrepos > 56567 Neuwied, Germany > +49 (0) 2631 9772-243 > https://www.researchgate.net/profile/Ivan_Calandra > > On 19/08/2020 17:07, Bert Gunter wrote: > > "&" is not a regex metacharacter. > > See ?regexp > > > > Bert Gunter > > > > "The trouble with having an open mind is that people keep coming > along > > and sticking things into it." > > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > > > > On Wed, Aug 19, 2020 at 7:53 AM Ivan Calandra <calandra at rgzm.de > <mailto:calandra at rgzm.de> > > <mailto:calandra at rgzm.de <mailto:calandra at rgzm.de>>> wrote: > > > >? ? ?Dear useRs, > > > >? ? ?I feel really stupid, but I cannot understand why "&" > doesn't work > >? ? ?as I > >? ? ?expect, while "|" does. > > > >? ? ?I have the following vector: > >? ? ?mydata <- c("SSFA-ConfoMap_GuineaPigs_NMPfilled.csv", > >? ? ?"SSFA-ConfoMap_Lithics_NMPfilled.csv",? > >? ? ?"SSFA-ConfoMap_Sheeps_NMPfilled.csv", > >? ? ?"SSFA-Toothfrax_GuineaPigs.xlsx", > >? ? ?"SSFA-Toothfrax_Lithics.xlsx", "SSFA-Toothfrax_Sheeps.xlsx") > >? ? ?and I want to find the values that include both "ConfoMap" and > >? ? ?"GuineaPigs". > > > >? ? ?If I do: > >? ? ?grep("ConfoMap&GuineaPigs", mydata, value=TRUE) > >? ? ?it returns an empty vector, character(0). > > > >? ? ?But if I do: > >? ? ?grep("ConfoMap|GuineaPigs", mydata, value=TRUE) > >? ? ?it returns all the elements that include either "ConfoMap" or > >? ? ?"GuineaPigs", as I would expect. > > > >? ? ?So what is wrong with my "&" construct? How can I return the > elements > >? ? ?that include both parts? > > > >? ? ?Thank you for your help! > >? ? ?Ivan > > > >? ? ?-- > >? ? ?Dr. Ivan Calandra > >? ? ?TraCEr, laboratory for Traceology and Controlled Experiments > >? ? ?MONREPOS Archaeological Research Centre and > >? ? ?Museum for Human Behavioural Evolution > >? ? ?Schloss Monrepos > >? ? ?56567 Neuwied, Germany > >? ? ?+49 (0) 2631 9772-243 > >? ? ?https://www.researchgate.net/profile/Ivan_Calandra > > > >? ? ?______________________________________________ > >? ? ?R-help at r-project.org <mailto:R-help at r-project.org> > <mailto:R-help at r-project.org <mailto:R-help at 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 at r-project.org <mailto:R-help at 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. >