Here is my toy data:
df <- tibble::tribble(
~var1, ~var2, ~var3, ~var4, ~var5, ~var6, ~var7,
"A", "C", 1L, 5L, "AA", "AB", 1L,
"A", "C", 2L, 5L, "BB", "AC", 2L,
"A", "D", 1L, 7L, "AA", "BC", 2L,
"A", "D", 2L, 3L, "BB", "CC", 1L,
"B", "C", 1L, 8L, "AA", "AB", 1L,
"B", "C", 2L, 6L, "BB", "AC", 2L,
"B", "D", 1L, 9L, "AA", "BC", 2L,
"B", "D", 2L, 6L, "BB", "CC", 1L)
My original question at the following link https://stackoverflow.com/a/53110342/6762788 was:
How can I get the combination of a minimum number of variables that uniquely identify the observations in the dataframe i.e which variables together can make the primary key? The following answer/code works absolutely fine, thanks so much to thelatemail.
nms <- unlist(lapply(seq_len(length(df)), combn, x=names(df), simplify=FALSE), rec=FALSE)
out <- data.frame(
vars = vapply(nms, paste, collapse=",", FUN.VALUE=character(1)),
counts = vapply(nms, function(x) nrow(unique(df[x])), FUN.VALUE=numeric(1))
)
Now, to make it work on big data, I want to take this to SparkR. Leveraging this answer, how can I translate this code in SparkR? If it's difficult in SparkR, then I can use sparklyr.