# 05 Results.r
DT.Customers

# How many customers total
# How many customers listened to first play
# How many to each


Total_Number_Of_Unique_Customers_On_iTunes <- DT.Customers[, lunique(customer_identifier)]

Unique_Customers_byRelease <- DT.Customers[, list(Unique_Customers=sum(owns)), by=release]

## No rows with more than one count
DT.Customers[(promo_was_gateway)][, list(release, count=lunique(releaseid)), by=customer_identifier][count>1]

DT.Customers[(promo_was_gateway)][, table(release)]


## Talley up each combination
setkeyIfNot(DT.Customers, release)
releases <- DT.Customers[, unique(release)]

## First, find all possible combinations
AllCombs <- 
lapply(seq(releases), function(i)
  combn(releases, i, simplify=FALSE))

AllCombs <- unlist(AllCombs, recursive=FALSE)

setattr(AllCombs, "names", sapply(AllCombs, pasteQ, q="[ ", qr=" ]", w="", C="  AND  "))


counts <- 
lapply(AllCombs, function(rr)
     DT.Customers[rr, sum(owns), by=customer_identifier][, sum(V1==length(rr))]
)

counts[sapply(counts, "!=", 0)]
