Skip to content
Prev 299608 / 398503 Next

unique vs duplicate problem

Hi Peter,

Thanks for testing it and notifying.? I didn't test it to other situtations.

Probably this should give similar results as Rui's
#Test 1:

x<-c(1,2,3,3,3,4,4,5)
func1<-function(x) !is.na(match(x,x[duplicated(x)]))
func1(x)
#[1] FALSE FALSE? TRUE? TRUE? TRUE? TRUE? TRUE FALSE

x[!func1(x)]
#[1] 1 2 5


#Rui's function?fun<-function(x) x%in%x[duplicated(x)]
?fun(x)
#[1] FALSE FALSE? TRUE? TRUE? TRUE? TRUE? TRUE FALSE
?identical(func1(x),fun(x))
#[1] TRUE

#Test2:
x2<-c(1,2,-1,-1,2,3,4,-4,4,5,5,5,6,7)
?x2[!func1(x2)]
#[1]? 1? 3 -4? 6? 7

identical(func1(x2),fun(x2))
#[1] TRUE

A.K.







----- Original Message -----
From: Peter Ehlers <ehlers at ucalgary.ca>
To: arun <smartpink111 at yahoo.com>
Cc: Nico902 <descostes at ciml.univ-mrs.fr>; R help <r-help at r-project.org>
Sent: Monday, July 9, 2012 4:14 PM
Subject: Re: [R] unique vs duplicate problem
On 2012-07-09 11:07, arun wrote:
Try the above approach with
?  x <- c(1,2,3,3,3,4,4,5)

I think Rui's solution is preferable.

Peter Ehlers