as.data.table.clv.data: Coerce to a Data Table

View source: R/f_s3generics_clvdata.R

as.data.table.clv.dataR Documentation

Coerce to a Data Table

Description

Extract a copy of the transaction data stored in the given clv.data object into a data.table.

Usage

## S3 method for class 'clv.data'
as.data.table(
  x,
  keep.rownames = FALSE,
  Ids = NULL,
  sample = c("full", "estimation", "holdout"),
  ...
)

Arguments

x

An object of class clv.data.

keep.rownames

Ignored

Ids

Character vector of customer ids for which transactions should be extracted. NULL extracts all.

sample

Name of sample for which transactions should be extracted, either "estimation", "holdout", or "full" (default).

...

Ignored

Value

A data.table with columns Id, Date, and Price (if present).

Examples

library(data.table)
 
data("cdnow")
clv.data.cdnow <- clvdata(data.transactions = cdnow,
                          date.format="ymd",
                          time.unit = "w",
                          estimation.split = 37)

# Extract all transaction data (all Ids, estimation and holdout period)
dt.trans <- as.data.table(clv.data.cdnow)

# Extract transaction data of estimation period
dt.trans <- as.data.table(clv.data.cdnow, sample="estimation")

# Extract transaction data of Ids "1", "2", and "999"
#  (estimation and holdout period)
dt.trans <- as.data.table(clv.data.cdnow, Ids = c("1", "2", "999"))

# Extract transaction data of Ids "1", "2", and "999" in estimation period
dt.trans <- as.data.table(clv.data.cdnow, Ids = c("1", "2", "999"),
                          sample="estimation")



CLVTools documentation built on Oct. 24, 2023, 1:06 a.m.