I am having troubles changing my basket data to transaction type data, I've tried the following 4 codes:
tr = as(dummy.basket$baskets, "transactions")
Error in as(dummy.basket$baskets, "transactions") :
no method or default for coercing “character” to “transactions”
tr = as(dummy.basket, "transactions")
Warning message:
Column(s) 1 not logical or factor. Applying default discretization (see '? discretizeDF').
tr <- read.transactions(dummy.basket, format= 'basket', sep = ',')
Error in readLines(file, encoding = encoding) : 'con' is not a connection
This is the summary for the file:
summary (dummy.basket)
baskets
Length:13683
Class :character
Mode :character
And these are the packages I have:
library(tidyverse)
library(readxl)
library(knitr)
library(ggplot2)
library(lubridate)
library(arules)
library(arulesViz)
library(plyr)
Thank you for your response. I think it's part of the arules package? If there isn't a method for as() "transactions. Do you know how I can change my data into transaction-type data? Thank you!
I have tried the following, for your first 4 lines of data and worked well for me.
First, from your excel file remove the first line which contains the title "baskets".
then save your excel file as "dummy.basket.csv" to your working directory.
then you will need 3 libraries for the apriori algorithm
library(arules)
library(arulesViz)
library(RColorBrewer)
dummy.basket <- read.transactions("dummy.basket.csv")
dummy.basket
#
# > dummy.basket
# transactions in sparse format with
# 5 transactions (rows) and
# 7 items (columns)
str(dummy.basket)
# Formal class 'transactions' [package "arules"] with 3 slots
# ..@ data :Formal class 'ngCMatrix' [package "Matrix"] with 5 slots
# .. .. ..@ i : int [1:9] 1 0 5 2 4 3 6 2 6
# .. .. ..@ p : int [1:6] 0 1 3 5 7 9
# .. .. ..@ Dim : int [1:2] 7 5
# .. .. ..@ Dimnames:List of 2
# .. .. .. ..$ : NULL
# .. .. .. ..$ : NULL
# .. .. ..@ factors : list()
# ..@ itemInfo :'data.frame': 7 obs. of 1 variable:
# .. ..$ labels: chr [1:7] "Bags," "baskets" "Belts" "MBG" ...
# ..@ itemsetInfo:'data.frame': 0 obs. of 0 variables
I just tried it and I am getting the below instead of what you are getting!
"Error in readLines(file, encoding = encoding) : 'con' is not a connection"