R filter data and count unique records
2 answers
You can try using the data.table package, for example:
> library(data.table)
> as.data.table(dat)[, .N, by = names(dat)]
A B C D N
1: 1 1 1 1 2
2: 2 2 1 2 2
3: 2 2 2 2 1
Or similar to "dplyr":
> library(dplyr)
> dat %>% group_by_(.dots = names(dat)) %>% summarise(n = n())
Source: local data frame [3 x 5]
Groups: A, B, C
A B C D n
1 1 1 1 1 2
2 2 2 1 2 2
3 2 2 2 2 1
+4
source to share