unique() duplicate() not what i am looking for

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

unique() duplicate() not what i am looking for

Knut Krueger-8
It should be simple but i do not find the right keywords:


Dup =  c(1,2,3,4,1,2,3,5)

I need 4,5 as result

unique(Dup) gives me [1] 4 1 2 3 5

duplicated(Dup) gives me
[1] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE

I need
[1] TRUE TRUE TRUE FALSE  TRUE  TRUE  TRUE FALSE


Kind regards Knut

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: unique() duplicate() not what i am looking for

PIKAL Petr
Hi

Dup %in% Dup[duplicated(Dup)]

Dup[!(Dup %in% Dup[duplicated(Dup)])]

Cheers
Petr

> -----Original Message-----
> From: R-help <[hidden email]> On Behalf Of Knut Krueger
> Sent: Monday, November 19, 2018 3:42 PM
> To: [hidden email] >> r-help mailing list <[hidden email]>
> Subject: [R] unique() duplicate() not what i am looking for
>
> It should be simple but i do not find the right keywords:
>
>
> Dup =  c(1,2,3,4,1,2,3,5)
>
> I need 4,5 as result
>
> unique(Dup) gives me [1] 4 1 2 3 5
>
> duplicated(Dup) gives me
> [1] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE
>
> I need
> [1] TRUE TRUE TRUE FALSE  TRUE  TRUE  TRUE FALSE
>
>
> Kind regards Knut
>
> ______________________________________________
> [hidden email] 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.
Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner’s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: unique() duplicate() not what i am looking for

PIKAL Petr
In reply to this post by Knut Krueger-8
Hi

and maybe sloightly less complicated

setdiff(Dup,Dup[duplicated(Dup)])

Cheers
Petr

> -----Original Message-----
> From: R-help <[hidden email]> On Behalf Of Knut Krueger
> Sent: Monday, November 19, 2018 3:42 PM
> To: [hidden email] >> r-help mailing list <[hidden email]>
> Subject: [R] unique() duplicate() not what i am looking for
>
> It should be simple but i do not find the right keywords:
>
>
> Dup =  c(1,2,3,4,1,2,3,5)
>
> I need 4,5 as result
>
> unique(Dup) gives me [1] 4 1 2 3 5
>
> duplicated(Dup) gives me
> [1] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE
>
> I need
> [1] TRUE TRUE TRUE FALSE  TRUE  TRUE  TRUE FALSE
>
>
> Kind regards Knut
>
> ______________________________________________
> [hidden email] 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.
Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner’s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: unique() duplicate() not what i am looking for

Rui Barradas
In reply to this post by Knut Krueger-8
Hello,

Try

i <- !(duplicated(Dup) | duplicated(Dup, fromLast = TRUE))
Dup[i]


or in one line, I post it like this to make it more clear.

Hope this helps,

Rui Barradas

Às 14:41 de 19/11/2018, Knut Krueger escreveu:

> It should be simple but i do not find the right keywords:
>
>
> Dup =  c(1,2,3,4,1,2,3,5)
>
> I need 4,5 as result
>
> unique(Dup) gives me [1] 4 1 2 3 5
>
> duplicated(Dup) gives me
> [1] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE
>
> I need
> [1] TRUE TRUE TRUE FALSE  TRUE  TRUE  TRUE FALSE
>
>
> Kind regards Knut
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: unique() duplicate() not what i am looking for

Fox, John
In reply to this post by Knut Krueger-8
Dear Knut,

Here's one way:

> as.vector((table(Dup) > 1)[Dup])
[1]  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE FALSE

Someone will probably think of something cleverer.

I hope this helps,
 John

--------------------------------------
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
Web: socialsciences.mcmaster.ca/jfox/



> -----Original Message-----
> From: R-help [mailto:[hidden email]] On Behalf Of Knut
> Krueger
> Sent: Monday, November 19, 2018 9:42 AM
> To: [hidden email] >> r-help mailing list <[hidden email]>
> Subject: [R] unique() duplicate() not what i am looking for
>
> It should be simple but i do not find the right keywords:
>
>
> Dup =  c(1,2,3,4,1,2,3,5)
>
> I need 4,5 as result
>
> unique(Dup) gives me [1] 4 1 2 3 5
>
> duplicated(Dup) gives me
> [1] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE
>
> I need
> [1] TRUE TRUE TRUE FALSE  TRUE  TRUE  TRUE FALSE
>
>
> Kind regards Knut
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.