Returns a subset of the transaction data stored within the given clv.data
object which meet conditions.
The given expression are forwarded to the data.table
of transactions.
Possible rows to subset and select are Id
, Date
, and Price
(if present).
# S3 method for clv.data
subset(x, subset, select, sample = c("full", "estimation", "holdout"), ...)
A copy of the data.table
of selected transactions. May contain columns Id
, Date
, and Price
.
clv.data
to subset
logical expression indicating rows to keep
expression indicating columns to keep
Name of sample for which transactions should be extracted,
further arguments passed to data.table::subset
data.table
's subset
# dont test because ncpu=2 limit on cran (too fast)
library(data.table) # for between()
data(cdnow)
clv.cdnow <- clvdata(cdnow,
date.format="ymd",
time.unit = "week",
estimation.split = "1997-09-30")
# all transactions of customer "1"
subset(clv.cdnow, Id=="1")
subset(clv.cdnow, subset = Id=="1")
# all transactions of customer "111" in the estimation period...
subset(clv.cdnow, Id=="111", sample="estimation")
# ... and in the holdout period
subset(clv.cdnow, Id=="111", sample="holdout")
# all transactions of customers "1", "2", and "999"
subset(clv.cdnow, Id %in% c("1","2","999"))
# all transactions on "1997-02-16"
subset(clv.cdnow, Date == "1997-02-16")
# all transactions between "1997-02-01" and "1997-02-16"
subset(clv.cdnow, Date >= "1997-02-01" & Date <= "1997-02-16")
# same using data.table's between
subset(clv.cdnow, between(Date, "1997-02-01","1997-02-16"))
# all transactions with a value between 50 and 100
subset(clv.cdnow, Price >= 50 & Price <= 100)
# same using data.table's between
subset(clv.cdnow, between(Price, 50, 100))
# only keep Id of transactions on "1997-02-16"
subset(clv.cdnow, Date == "1997-02-16", "Id")
Run the code above in your browser using DataLab