First I have to make a table for observation (given as a factor for getting zero cells), then a hash of each table and calculate that:
require(magrittr)
require(digest)
data<-c("QK", "KQ", "JKQZ", "KJZ")
tbl <- strsplit(data, "") %>% lapply(factor,levels=c("K","Q", "J", "Z")) %>%
lapply(table) %>% do.call(what=rbind)
tbl
which gives the following:
K Q J Z
[1,] 1 1 0 0
[2,] 1 1 0 0
[3,] 1 1 1 1
[4,] 1 0 1 1
Then hash and count:
h <- apply(tbl, 1, digest)
tbl <- cbind(tbl, count=as.vector(table(h)[h]))
tbl <- tbl[!duplicated(h), ]
Here is the result:
K Q J Z count
[1,] 1 1 0 0 2
[2,] 1 1 1 1 1
[3,] 1 0 1 1 1
source
share