I am looking to use the arulesSequences
package in R. However, I have no idea as to how to coerce my data frame into an object that can leverage this package.
Here is a toy dataset that replicates my data structure:
ids <- c(rep("X", 5), rep("Y", 5), rep("Z", 5))
seq <- rep(1:5,3)
val <- sample(LETTERS, 15, replace=T)
df <- data.frame(ids, seq, val)
df
ids seq val
1 X 1 T
2 X 2 H
3 X 3 V
4 X 4 A
5 X 5 X
6 Y 1 D
7 Y 2 B
8 Y 3 A
9 Y 4 D
10 Y 5 P
11 Z 1 Q
12 Z 2 R
13 Z 3 W
14 Z 4 W
15 Z 5 P
Any help will be greatly appreciated.
Factor data frame:
df_fact = data.frame(lapply(df,as.factor))
Build "transaction" data:
df_trans = as(df_fact, 'transactions')
Test it:
itemFrequencyPlot(df_trans, support = 0.1, cex.names=0.8)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With