[R] A question on Duplicating
Keith Jewell
k.jewell at campden.co.uk
Thu Feb 10 10:09:41 CET 2011
Unless I've made a mistake (it happens!) that gives FALSE on the data which
the OP said should give TRUE.
Ravi Varadhan suggested
duplicated(a) & duplicated(b)
but that gives the same result for
b <- c("n", "m", "o", "m")
for which I think the OP would like FALSE
I think this may do it
all((a %in% a[duplicated(a)]) == (b %in% b[duplicated(b)]))
Hope that helps
Keith J
<rex.dwyer at syngenta.com> wrote in message
news:36180405F8418449918AD20618D110FC094E9DB3AE at USETCMSXMB02.NAFTA.SYNGENTA.ORG...
> ab = paste(a,b,sep=";~;~;~")
> flag = length(ab)==length(unique(ab))
>
> This should work unless you use 3 consecutive winking elephants in other
> places in your program.
>
>
>
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Nipesh Bajaj
> Sent: Wednesday, February 09, 2011 10:12 AM
> To: r-help at r-project.org
> Subject: [R] A question on Duplicating
>
> Hello I am struggling to accomplice an idea which is as follows:
>
> I have a vector say: a <- c("a", "b", "c", "a") and another: b <- c("m",
> "n", "o", "m"). Length of those 2 vectors are essentially be same. Here
> task
> is to check the duplicates in the vector 'a' and then to check whether any
> duplicates are there in the same places of 'b'. If not, flag a FALSE.
>
> I above example, it is correct hence TRUE. However in general how can I
> implement this?
>
> Can somebody please help me?
>
> Thanks,
>
> [[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.
>
>
>
>
> message may contain confidential information. If you are not the
> designated recipient, please notify the sender immediately, and delete the
> original and any copies. Any use of the message by you is prohibited.
More information about the R-help
mailing list