[R] duplicates including first occurrence

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Mon Jan 28 12:51:37 CET 2019


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
> 
> ______________________________________________
> R-help using 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.



More information about the R-help mailing list