I have a data frame that I’m trying to coerce into a transactions object for analysis using the arules
package. Here is a reproducible example for my question:
df <- data.frame(
case_number = c("1001", "1001", "1002", "1002", "1003"),
date = as.Date(c("2016-04-19", "2016-04-21", "2016-05-21", "2016-05-25",
"2016-06-14")),
happy = factor(c("Yes", "No", "Yes", "No", "No")),
food = ordered(
c(1, 2, 1, 3, 1),
levels = c(1, 2, 3),
labels = c("A lot", "Some", "None")
),
stringsAsFactors = FALSE
)
df
case_number date happy food
1 1001 2016-04-19 Yes A lot
2 1001 2016-04-21 No Some
3 1002 2016-05-21 Yes A lot
4 1002 2016-05-25 No None
5 1003 2016-06-14 No A lot
I have no trouble coercing if I drop case_numer and date. However, in the introduction to arules, example 1, a summary of the Epub transactions object includes the following:
includes extended transaction information - examples:
transactionID TimeStamp
10792 session_4795 2003-01-01 19:59:00
10793 session_4797 2003-01-02 06:46:01
10794 session_479a 2003-01-02 09:50:38
You can recreate this yourself using the following code:
library(arules)
data(Epub)
summary(Epub)
My question is, how do I add case_number
and date
as extended transaction information as above. I’ve looked through the arules documentation and this SO post.