You can use duplicated
to subset the data and then call table
:
table(subset(df, !duplicated(paste(col1, col2)), select = col1)) #app chh gg # 1 1 2
As a second option, here is the dplyr approach:
library(dplyr) distinct(df) %>% count(col1) # or distinct(df, col1, col2) if you have other columns #Source: local data frame [3 x 2] # # col1 n # (fctr) (int) #1 app 1 #2 chh 1 #3 gg 2
source share