How to Apply the duplicated Function in R (Example Code)
In this tutorial you’ll learn how to use the duplicated command in the R programming language.
Example: Applying duplicated() Function to Elements of Vector
x <- c(1:3, 2:4) # Constructing example vector x # Displaying vector in RStudio console # [1] 1 2 3 2 3 4 |
x <- c(1:3, 2:4) # Constructing example vector x # Displaying vector in RStudio console # [1] 1 2 3 2 3 4
duplicated(x) # Return logical vector # [1] FALSE FALSE FALSE TRUE TRUE FALSE |
duplicated(x) # Return logical vector # [1] FALSE FALSE FALSE TRUE TRUE FALSE
x[!duplicated(x)] # Subset unique vector elements # [1] 1 2 3 4 |
x[!duplicated(x)] # Subset unique vector elements # [1] 1 2 3 4