Some time ago I asked a question about creating data about a basket. Now I would like to create a similar data.frame file, but based on the third variable. Unfortunately, I run into problems. Previous question: An effective way to create a market basket matrix in R
@shadow and @ SimonO101 gave me good answers, but I could not change their anwser correctly. I have the following data:
Customer <- as.factor(c(1000001,1000001,1000001,1000001,1000001,1000001,1000002,1000002,1000002,1000003,1000003,1000003))
Product <- as.factor(c(100001,100001,100001,100004,100004,100002,100003,100003,100003,100002,100003,100008))
input <- data.frame(Customer,Product)
I can create an emergency table as follows:
input_df <- as.data.frame.matrix(table(input))
However, I have a third (numeric) variable that I want as output in the table.
Number <- c(3,1,-4,1,1,1,1,1,1,1,1,1)
input <- data.frame(Customer,Product,Number)
(, 3 ) . , , . Number ( 0, ), :
input_agg <- aggregate( Number ~ Customer + Product, data = input, sum)
, , , - .