Learn R Programming

CLVTools (version 0.11.2)

as.data.frame.clv.data: Coerce to a Data Frame

Description

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

Usage

# S3 method for clv.data
as.data.frame(
  x,
  row.names = NULL,
  optional = NULL,
  ids = NULL,
  sample = c("full", "estimation", "holdout"),
  ...
)

Value

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

Arguments

x

An object of class clv.data.

row.names

Ignored

optional

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

Examples

Run this code
 # \donttest{
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)
df.trans <- as.data.frame(clv.data.cdnow)

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

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

# Extract transaction data of ids "1", "2", and "999" in estimation period
df.trans <- as.data.frame(clv.data.cdnow, ids = c("1", "2", "999"),
                          sample="estimation")
# }

Run the code above in your browser using DataLab