> x <- c(1, 1, 4, 5, 4, 6)

 

> duplicated(x)

[1] FALSE  TRUE FALSE FALSE  TRUE FALSE

 

 

> x[duplicated(x)] # 중복된 애들 하나씩만 나열; 1,4=중복됨

[1] 1 4

 

> x[duplicated(x) | duplicated(x, fromLast = T)]

# 모든 중복된 애들; 1, 1, 4, 4

[1] 1 1 4 4

 

 

> # 중복된 애들 제거하고 나열

> x[! duplicated(x)]

[1] 1 4 5 6

> unique(x)

[1] 1 4 5 6

 

 

> # Remove duplicated rows based on col1 and col2

> library(dplyr)

> distinct(data, col1, col2)


+ Recent posts