0

I have got data frame with the rows (5000000) as customers and rows(500) as products.

Cust/Pro  P1  P2   P3  P4
C1        1     0  0   1
C2        0     1  0   1
C3        1     1  0   0
C4        1     0  1   1

I want to convert this into

   P1  P2 P3  P4
P1 3   0  1   2
P2 0   2  0   1
P3 1   0  1   1
P4 2   1  1   3

It also needs to be efficient since the data frame size is also big. Tried correlation and cos product of matrix. No getting the exact result.

Sotos
  • 51,121
  • 6
  • 32
  • 66
Karthik
  • 35
  • 3
  • Care to explain the logic behind the transformation? – Sotos Sep 15 '17 at 12:06
  • 2
    This is a crossproduct: `crossprod(as.matrix(dat[-1]))` and a duplicate question (if better explained of course). – lmo Sep 15 '17 at 12:08
  • This format is best for comparing it with other data frames of similar nature and understanding. – Karthik Sep 15 '17 at 12:11
  • The answers to this question: https://stackoverflow.com/questions/13281303/creating-co-occurrence-matrix might be helpful – missuse Sep 15 '17 at 12:50

0 Answers0