Skip to content

Instantly share code, notes, and snippets.

def tuple_filter(tupl):
count = 0
for transaction in transactions:
if all(e in transaction for e in tupl):
count += 1
if count >= threshold_count:
return True
sample.interval=20000
"readLines" "strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source"
"readLines" "strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source"
"readLines" "strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source"
"readLines" "strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source"
"readLines" "strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source"
"readLines" "strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source"
"strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source"
"strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source"
"strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source"
Rprof()
# Read a list of about about 100K vectors, each with fewer than 30 items
# (most with a few). These are supermarket-type transactions.
transactions = lapply(strsplit(readLines('Data/retail.dat'), ' '), as.numeric)
transactions.unlisted = unlist(transactions)
# Count the total number of items over all transactions.
nitems = length(transactions.unlisted)
# And the number of occurrences of each item.
counts = table(transactions.unlisted)
def bcd_to_int(bcd_int):
'''Convert a BCD integer to a base-10 integer.'''
bcd_str = bin(bcd_int)[2:][::-1]
num_groups = ((len(bcd_str) - 1) / 4) + 1
total = 0
for i in range(num_groups):
digit = bcd_str[(4 * i):(4 * (i + 1))][::-1]
total += int(digit, 2) * (10 ** i)