I have a data frame and it looks like this:
str(df)
'data.frame': 174671 obs. of 3 variables:
$ COD_PRODUCT: Factor w/ 338 levels "001CH","002CO",..: 1 1 1 1 1 1 1 1 1 1 ...
$ STORE : Factor w/ 15 levels "Barcelona","Florencia",..: 4 13 4 5 11 12 5 13 1 12 ...
$ SELL_ID : Factor w/ 74327 levels "BA0000000","BA0000001",..: 28696 65976 27147 14291 51141 59023 12249 61636 5495 59314 ...
There is neither NAs nor invalid values in these Factors, as we can see here:
print(unlist(lapply(df, function(x) any(is.na(x)))))
COD_PRODUCT STORE SELL_ID
FALSE FALSE FALSE
My goal is to create a data mining model (association rules) and for that, I had previously successful imported the package arules. The next step that I followed was to split my df into a list and apply an operation to eliminate duplicated occurrences, such as:
ppvt <- split(x = df[, c("COD_PRODUCT", "STORE")], f = df$SELL_ID)
ppvt <- lapply (ppvt, unique)
So far, everything works fine. However, when I tried to transform into transactions:
ppvt <- as (ppvt, "transactions" )
I'm getting an error message:
Error in asMethod(object) : can coerce list with atomic components only
Totally clueless about it (and yes, as you can imagine, I searched a lot on the Internet before coming here). Do you have an idea about how to solve it?
Any help will be really appreciated.
Regards,
str(ppvt)
, and you will see that each element of the list is a dataframe. In order to convert to transactions you need each element of the list to be a vector. – Esther