実装はおそらく最適ではありませんが、改善することができます。
library(stringi)
library(arules)
library(purrr)
shopping_items <- c("apple banana", "orange", "tea orange beef")
str <- paste(shopping_items,collapse = ' ')
# unique items
str_un <- unique(unlist(stri_split_fixed(str,' ')))
# create a dataframe with dimensions:
# length(shopping_items) x length(str_un)
df <- as.data.frame(matrix(rep(0,length(str_un)*length(shopping_items)),ncol=length(str_un)))
names(df) <- str_un
# positions of 1's in each column
vecs <- map(str_un,grep,shopping_items)
sapply(1:length(str_un), function(x) df[,x][vecs[[x]]] <<- 1)
df[] <- lapply(df,as.factor)
# Generate a transactions dataset.
tr <- as(df, "transactions")
# Generate the association rules.
# rules <- apriori(tr, ...