Skip to content

Instantly share code, notes, and snippets.

@rtirrell
Created January 7, 2011 22:57
Show Gist options
  • Save rtirrell/770257 to your computer and use it in GitHub Desktop.
Save rtirrell/770257 to your computer and use it in GitHub Desktop.
transactions = lapply(strsplit(readLines('Data/retail.dat'), ' '), as.numeric)
transactions.unlisted = unlist(transactions)
nitems = length(transactions.unlisted)
counts = table(transactions.unlisted)
threshold.count = 0.02 * length(transactions)
frequent = list(
single = (1:length(counts))[counts > threshold.count]
)
frequent$cdouble = t(combn(frequent$single, 2))
rm.rows = c()
for (i in 1:nrow(frequent$cdouble)) {
if (sum(sapply(transactions, function(r) all(frequent$cdouble[i] %in% r))) < threshold.count) {
rm.rows = c(rm.rows, i)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment