An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090204/68e53dd6/attachment-0001.pl>
R command to compare two vectors?
7 messages · Jason Rupert, Jorge Ivan Velez, Greg Snow +4 more
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090204/b9a95076/attachment-0001.pl>
Try:
b_tmp %in% a_tmp
You may also want to use the all or any function with the above. Hope this helps,
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Jason Rupert
> Sent: Wednesday, February 04, 2009 4:50 PM
> To: R-help at r-project.org
> Subject: [R] R command to compare two vectors?
>
> By any chance is there an R command to compare two vectors?
>
> For example,
> a_tmp<-c("a", "b", "c", "d", "e", "f", "g", 'h')
> b_tmp<-c("a",?"c", "e", "g")
>
> I would like to compare b_tmp against a_tmp to determine if the members
> of b_tmp are part of a_tmp.
>
> I tried
> ?subset(b_tmp, b_tmp==a_tmp)
>
> That doesn't seem to work.
>
> Thanks again.
>
>
>
> [[alternative HTML version deleted]]
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090204/04307125/attachment-0001.pl>
Here is one other way: bnota <- setdiff(b_tmp, a_tmp) gives the members of b_tmp that are not in a_tmp so length(bnota) == 0 if all of b_tmp is in a_tmp. On Wed, Feb 4, 2009 at 6:56 PM, Jorge Ivan Velez
<jorgeivanvelez at gmail.com> wrote:
Dear Jason, Yes, here is one way:
a_tmp<-c("a", "b", "c", "d", "e", "f", "g", 'h')
b_tmp<-c("a", "c", "e", "g")
b_tmp %in% a_tmp
[1] TRUE TRUE TRUE TRUE
b_tmp[b_tmp%in%a_tmp]
[1] "a" "c" "e" "g"
all(b_tmp %in% a_tmp)
[1] TRUE Take a look at ?"%in%" and ?all for more information. HTH, Jorge On Wed, Feb 4, 2009 at 6:49 PM, Jason Rupert <jasonkrupert at yahoo.com> wrote:
By any chance is there an R command to compare two vectors?
For example,
a_tmp<-c("a", "b", "c", "d", "e", "f", "g", 'h')
b_tmp<-c("a", "c", "e", "g")
I would like to compare b_tmp against a_tmp to determine if the members of
b_tmp are part of a_tmp.
I tried
subset(b_tmp, b_tmp==a_tmp)
That doesn't seem to work.
Thanks again.
[[alternative HTML version deleted]]
______________________________________________ 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.
[[alternative HTML version deleted]]
______________________________________________ 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.
Try this:
a_tmp<-c("a", "b", "d", "e", "f", "g", 'h')
b_tmp<-c("a", "c", "e", "g")
setdiff(b_tmp, a_tmp)
[1] "c"
setdiff(a_tmp, b_tmp)
[1] "b" "d" "f" "h" Is this a bug? Jin -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Gabor Grothendieck Sent: Thursday, 5 February 2009 11:07 To: Jorge Ivan Velez Cc: R-help at r-project.org Subject: Re: [R] R command to compare two vectors? Here is one other way: bnota <- setdiff(b_tmp, a_tmp) gives the members of b_tmp that are not in a_tmp so length(bnota) == 0 if all of b_tmp is in a_tmp. On Wed, Feb 4, 2009 at 6:56 PM, Jorge Ivan Velez
<jorgeivanvelez at gmail.com> wrote:
Dear Jason, Yes, here is one way:
a_tmp<-c("a", "b", "c", "d", "e", "f", "g", 'h')
b_tmp<-c("a", "c", "e", "g")
b_tmp %in% a_tmp
[1] TRUE TRUE TRUE TRUE
b_tmp[b_tmp%in%a_tmp]
[1] "a" "c" "e" "g"
all(b_tmp %in% a_tmp)
[1] TRUE Take a look at ?"%in%" and ?all for more information. HTH, Jorge On Wed, Feb 4, 2009 at 6:49 PM, Jason Rupert <jasonkrupert at yahoo.com> wrote:
By any chance is there an R command to compare two vectors?
For example,
a_tmp<-c("a", "b", "c", "d", "e", "f", "g", 'h')
b_tmp<-c("a", "c", "e", "g")
I would like to compare b_tmp against a_tmp to determine if the members of
b_tmp are part of a_tmp.
I tried
subset(b_tmp, b_tmp==a_tmp)
That doesn't seem to work.
Thanks again.
[[alternative HTML version deleted]]
______________________________________________ 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.
[[alternative HTML version deleted]]
______________________________________________ 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.
______________________________________________ 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.
?setdiff Description Performs set union, intersection, (asymmetric!) difference, equality and membership on two vectors.
Note the (asymmetric) on difference. -Roy
On Feb 4, 2009, at 5:06 PM, Jin.Li at ga.gov.au wrote:
Try this:
a_tmp<-c("a", "b", "d", "e", "f", "g", 'h')
b_tmp<-c("a", "c", "e", "g")
setdiff(b_tmp, a_tmp)
[1] "c"
setdiff(a_tmp, b_tmp)
[1] "b" "d" "f" "h" Is this a bug? Jin -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org ] On Behalf Of Gabor Grothendieck Sent: Thursday, 5 February 2009 11:07 To: Jorge Ivan Velez Cc: R-help at r-project.org Subject: Re: [R] R command to compare two vectors? Here is one other way: bnota <- setdiff(b_tmp, a_tmp) gives the members of b_tmp that are not in a_tmp so length(bnota) == 0 if all of b_tmp is in a_tmp. On Wed, Feb 4, 2009 at 6:56 PM, Jorge Ivan Velez <jorgeivanvelez at gmail.com> wrote:
Dear Jason, Yes, here is one way:
a_tmp<-c("a", "b", "c", "d", "e", "f", "g", 'h')
b_tmp<-c("a", "c", "e", "g")
b_tmp %in% a_tmp
[1] TRUE TRUE TRUE TRUE
b_tmp[b_tmp%in%a_tmp]
[1] "a" "c" "e" "g"
all(b_tmp %in% a_tmp)
[1] TRUE Take a look at ?"%in%" and ?all for more information. HTH, Jorge On Wed, Feb 4, 2009 at 6:49 PM, Jason Rupert <jasonkrupert at yahoo.com> wrote:
By any chance is there an R command to compare two vectors?
For example,
a_tmp<-c("a", "b", "c", "d", "e", "f", "g", 'h')
b_tmp<-c("a", "c", "e", "g")
I would like to compare b_tmp against a_tmp to determine if the
members of
b_tmp are part of a_tmp.
I tried
subset(b_tmp, b_tmp==a_tmp)
That doesn't seem to work.
Thanks again.
[[alternative HTML version deleted]]
______________________________________________ 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.
[[alternative HTML version deleted]]
______________________________________________ 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.
______________________________________________ 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. ______________________________________________ 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.
********************** "The contents of this message do not reflect any position of the U.S. Government or NOAA." ********************** Roy Mendelssohn Supervisory Operations Research Analyst NOAA/NMFS Environmental Research Division Southwest Fisheries Science Center 1352 Lighthouse Avenue Pacific Grove, CA 93950-2097 e-mail: Roy.Mendelssohn at noaa.gov (Note new e-mail address) voice: (831)-648-9029 fax: (831)-648-8440 www: http://www.pfeg.noaa.gov/ "Old age and treachery will overcome youth and skill." "From those who have been given much, much will be expected"