With the RWE below, I am one step short of achieving my desired result. I can identify the unique combinations, but I want to obtain a data.table of all three columns (A
,B
and C
)
a <- c(1,1,1,1,1,2,3,4,5,5,5,6,6,7,7,8,8,9,9,9,9,9,10,10,10)
b <- c(1,2,1,1,5,5,6,1,1,1,3,2,2,1,1,2,3,1,2,3,4,4,1,2,2)
c <- c(1,1,3,1,1,2,3,4,5,5,5,6,6,7,7,8,8,9,9,9,9,9,10,10,20)
df1 <- data.frame(a, b, c)
head(df1)
#
library(dplyr) # example using dplyr package
df1 %>%
distinct(a,b)
#
unique( df1[ , 1:2 ] ) # using base R
These commands return the unique combinations of a
AND b
from df1
, but I want the output to include the c
values in the data.frame also.