Using “dat” from either of the answers above, try crossprod
and table
:
V <- crossprod(table(dat[1:2]))
diag(V) <- 0
V
# Items
# Items A B C D E F
# A 0 1 1 1 1 0
# B 1 0 3 1 1 1
# C 1 3 0 1 0 1
# D 1 1 1 0 1 1
# E 1 1 0 1 0 0
# F 0 1 1 1 0 0
More Related Contents:
- Matrix operation in R: I have a square matrix whose determinant is zero, i need to find its inverse in R programing. Is it possible ,if yes how? [closed]
- Loop through a R matrix row-wise and print elements [duplicate]
- Convert an upper to lower triangle matrix in r [duplicate]
- R memory management / cannot allocate vector of size n Mb
- Split a large dataframe into a list of data frames based on common value in column
- How to subset matrix to one column, maintain matrix data type, maintain row/column names?
- Multiply rows of matrix by vector?
- All Levels of a Factor in a Model Matrix in R
- How to divide each row of a matrix by elements of a vector in R
- Subscript out of bounds – general definition and solution?
- How can I create a correlation matrix in R?
- Apply a function to every row of a matrix or a data frame
- Rotate a Matrix in R by 90 degrees clockwise
- R – How to get row & column subscripts of matched elements from a distance matrix
- Create dataframe from a matrix
- Get row and column indices of matches using `which()`
- Finding row index containing maximum value using R
- How `poly()` generates orthogonal polynomials? How to understand the “coefs” returned?
- Function to split a matrix into sub-matrices in R
- Loop in R: how to save the outputs?
- Last Observation Carried Forward In a data frame? [duplicate]
- Should I use a data.frame or a matrix?
- Find K nearest neighbors, starting from a distance matrix
- Select rows of a matrix that meet a condition
- R: How to rescale my matrix by column
- Calculate Euclidean distance matrix using a big.matrix object
- R reshape a vector into multiple columns
- fast large matrix multiplication in R
- How to calculate adjacency matrices in R
- What does the error “arguments imply differing number of rows: x, y” mean?