duplicates including first occurrence

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

duplicates including first occurrence

R help mailing list-2
Ho to all

i get the  results

mtcars[duplicated(mtcars$wt,fromLast=TRUE),]
Hornet Sportabout 18.7   8 360.0 175 3.15 3.44 17.02  0  0    3    2
Duster 360        14.3   8 360.0 245 3.21 3.57 15.84  0  0    3    4
Merc 280          19.2   6 167.6 123 3.92 3.44 18.30  1  0    4    4


mtcars[duplicated(mtcars$wt),]

Merc 280      19.2   6 167.6 123 3.92 3.44 18.3  1  0    4    4
Merc 280C     17.8   6 167.6 123 3.92 3.44 18.9  1  0    4    4
Maserati Bora 15.0   8 301.0 335 3.54 3.57 14.6  0  1    5    8


The first occurrence is missing - is there any possibility to get

Hornet Sportabout 18.7   8 360.0 175 3.15 3.44 17.02  0  0    3    2
Merc 280          19.2   6 167.6 123 3.92 3.44 18.30  1  0    4    4
Merc 280C         17.8   6 167.6 123 3.92 3.44 18.90  1  0    4    4
Duster 360    14.3   8  360 245 3.21 3.57 15.84  0  0    3    4
Maserati Bora 15.0   8  301 335 3.54 3.57 14.60  0  1    5    8


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: duplicates including first occurrence

Rui Barradas
Hello,

Simply OR (|) both conditions.

mtcars[duplicated(mtcars$wt) | duplicated(mtcars$wt,fromLast=TRUE),]
#                   mpg cyl  disp  hp drat   wt  qsec vs am gear carb
#Hornet Sportabout 18.7   8 360.0 175 3.15 3.44 17.02  0  0    3    2
#Duster 360        14.3   8 360.0 245 3.21 3.57 15.84  0  0    3    4
#Merc 280          19.2   6 167.6 123 3.92 3.44 18.30  1  0    4    4
#Merc 280C         17.8   6 167.6 123 3.92 3.44 18.90  1  0    4    4
#Maserati Bora     15.0   8 301.0 335 3.54 3.57 14.60  0  1    5    8


Hope this helps,

Rui Barradas

Às 11:43 de 28/01/2019, Knut Krueger via R-help escreveu:

> Ho to all
>
> i get the  results
>
> mtcars[duplicated(mtcars$wt,fromLast=TRUE),]
> Hornet Sportabout 18.7   8 360.0 175 3.15 3.44 17.02  0  0    3    2
> Duster 360        14.3   8 360.0 245 3.21 3.57 15.84  0  0    3    4
> Merc 280          19.2   6 167.6 123 3.92 3.44 18.30  1  0    4    4
>
>
> mtcars[duplicated(mtcars$wt),]
>
> Merc 280      19.2   6 167.6 123 3.92 3.44 18.3  1  0    4    4
> Merc 280C     17.8   6 167.6 123 3.92 3.44 18.9  1  0    4    4
> Maserati Bora 15.0   8 301.0 335 3.54 3.57 14.6  0  1    5    8
>
>
> The first occurrence is missing - is there any possibility to get
>
> Hornet Sportabout 18.7   8 360.0 175 3.15 3.44 17.02  0  0    3    2
> Merc 280          19.2   6 167.6 123 3.92 3.44 18.30  1  0    4    4
> Merc 280C         17.8   6 167.6 123 3.92 3.44 18.90  1  0    4    4
> Duster 360    14.3   8  360 245 3.21 3.57 15.84  0  0    3    4
> Maserati Bora 15.0   8  301 335 3.54 3.57 14.60  0  1    5    8
>
>
> 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: duplicates including first occurrence

Bert Gunter-2
... Alternatively(but probably less efficient):

## the indexing logical vector
with(mtcars, wt %in% wt[duplicated(wt)] )

cheers,
Bert




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 Mon, Jan 28, 2019 at 3:53 AM Rui Barradas <[hidden email]> wrote:

> Hello,
>
> Simply OR (|) both conditions.
>
> mtcars[duplicated(mtcars$wt) | duplicated(mtcars$wt,fromLast=TRUE),]
> #                   mpg cyl  disp  hp drat   wt  qsec vs am gear carb
> #Hornet Sportabout 18.7   8 360.0 175 3.15 3.44 17.02  0  0    3    2
> #Duster 360        14.3   8 360.0 245 3.21 3.57 15.84  0  0    3    4
> #Merc 280          19.2   6 167.6 123 3.92 3.44 18.30  1  0    4    4
> #Merc 280C         17.8   6 167.6 123 3.92 3.44 18.90  1  0    4    4
> #Maserati Bora     15.0   8 301.0 335 3.54 3.57 14.60  0  1    5    8
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 11:43 de 28/01/2019, Knut Krueger via R-help escreveu:
> > Ho to all
> >
> > i get the  results
> >
> > mtcars[duplicated(mtcars$wt,fromLast=TRUE),]
> > Hornet Sportabout 18.7   8 360.0 175 3.15 3.44 17.02  0  0    3    2
> > Duster 360        14.3   8 360.0 245 3.21 3.57 15.84  0  0    3    4
> > Merc 280          19.2   6 167.6 123 3.92 3.44 18.30  1  0    4    4
> >
> >
> > mtcars[duplicated(mtcars$wt),]
> >
> > Merc 280      19.2   6 167.6 123 3.92 3.44 18.3  1  0    4    4
> > Merc 280C     17.8   6 167.6 123 3.92 3.44 18.9  1  0    4    4
> > Maserati Bora 15.0   8 301.0 335 3.54 3.57 14.6  0  1    5    8
> >
> >
> > The first occurrence is missing - is there any possibility to get
> >
> > Hornet Sportabout 18.7   8 360.0 175 3.15 3.44 17.02  0  0    3    2
> > Merc 280          19.2   6 167.6 123 3.92 3.44 18.30  1  0    4    4
> > Merc 280C         17.8   6 167.6 123 3.92 3.44 18.90  1  0    4    4
> > Duster 360    14.3   8  360 245 3.21 3.57 15.84  0  0    3    4
> > Maserati Bora 15.0   8  301 335 3.54 3.57 14.60  0  1    5    8
> >
> >
> > 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[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.