Learn R Programming

BTYD (version 2.4)

dc.ReadLines: Read Lines

Description

Given a .csv file that throws errors when read in by the usual read.csv and read.table methods, loops through the file line-by-line and picks out the customer, date, and sales (optional) transaction data to return an event log.

Usage

dc.ReadLines(csv.filename, cust.idx, date.idx, sales.idx = -1)

Arguments

csv.filename
filename of the comma-delimited file to be read. It must contain headers.
cust.idx
index of the customer ID column in the comma-delimited file.
date.idx
index of the date column in the comma-delimited file.
sales.idx
index of the sales column in the comma-delimited file.

Value

Event log with columns labelled "cust" and "date". If sales data is included in the comma-delimited file, a "sales" column is included in the event log.

Details

Once this function has been run, you may need to convert the date column to Date objects for the event log to work with other functions in this library. See the as.Date function in the main package for more details.

Examples

Run this code
# Create event log from file "cdnowElog.csv", which has
# customer IDs in the second column, dates in the third column, and
# sales numbers in the fifth column.
elog <- dc.ReadLines(system.file("data/cdnowElog.csv", package="BTYD"),2,3,5)

# convert date column to date objects, as required by some other functions
elog$date <- as.Date(elog$date, "$Y%m%d")

Run the code above in your browser using DataLab