-2

I'm new to stackoverflow and to datascience. Right now i've got a project where i want to perform a association rule analysis. I've got some troubles with making the matrix for the analysis. My data is looking like this:

column 1: receiptnumber, column 2: brand, column 3: bought or not.

I would like to get a matrix whereby the receiptnumbers are the rows, and the brands are the columns. I've to say that not every receiptnumber has all the brands covert.

Uwe
  • 41,420
  • 11
  • 90
  • 134
Jasper1989
  • 69
  • 1
  • 7
  • Please provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) along with the expected output – digEmAll Feb 06 '17 at 13:05
  • Welcome to SO. Please have a read at [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and of course how to give [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Sotos Feb 06 '17 at 13:10

1 Answers1

0

I think the answer to this is as simple as creating a table. I'll provide a MWE:

data <- data.frame(receiptnumber = c('1', '1', '2', '3', '4'),
                   brand = c('A', 'A', 'B', 'C', 'D'))

print(data)

#   receiptnumber brand
# 1             1     A
# 2             1     A
# 3             2     B
# 4             3     C
# 5             4     D

tabData <- table(data$receiptnumber, data$brand)

print(tabData)

#   A B C D
# 1 2 0 0 0
# 2 0 1 0 0
# 3 0 0 1 0
# 4 0 0 0 1

Normal indexing still works

tabData[1,3]

# 0
Frost_Maggot
  • 309
  • 2
  • 12
  • Hi Frost maggot, I've tried the thing you mentioned above. When i tried to run it Rstudio gave the following error: "cannot allocate vector of size 1.9 gb. When i saw this happening i've tried to make a small subset (total of 791 observations) and ran it again. Rstudio gave the same error, so I think there is another problem but i can't find which. It should be fairly easy for R to make a matrix with so few datapoints right? Do you have any idea how I can solve this? Thanks for your help by the way, it is nice for a starter with R programming to aks certain experienced people about these probs – Jasper1989 Feb 06 '17 at 15:36