A more specific reproducible example.

set.seed(1023)
library(arules)

# starting from a dataframe whose fields are characters (see stringsAsFactors = 
FALSE), as asked
products <- c("P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10")
mydf <- data.frame(user = sample(LETTERS[1:20], 100, replace=T),
                   prod = sample(products, 100, replace=T),
                   stringsAsFactors=FALSE)
str(mydf)

# convert to factors
mydf$user <- factor(mydf$user)
mydf$prod <- factor(mydf$prod)

# splitting by user
prodlist <- split(x=mydf[,"prod"], f=mydf$user)
prodlist

# remove duplicates
prodlist <- lapply(prodlist, unique)
prod.trans <- as(prodlist, "transactions")
itemFrequency(prod.trans)

# generating rules
rules <- apriori(prod.trans,parameter=list(support=.1, confidence=.5))
inspect(rules)

--

Best,

GG





        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to