Description Usage Arguments Value Author(s) Examples
View source: R/cooccurrence_matrix.R
Given a document-topic matrix, the function returns a topic cooccurrence matrix (also called an adjacency matrix).
1 |
x |
A dataframe representing a document-topic matrix. Each row i and column j in the matrix should represent a document and topic, respectively. Each element x[i,j] can be either 1 if document i contains topic j, or 0 otherwise. |
A dataframe representing the topic cooccurrence matrix
Chinmay Kakatkar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | library(coocmat)
#simulate some data (rows are documents, cols are topics)
df <- data.frame(t(matrix(c(c(1,0,0,1,0,1),
c(0,1,1,1,0,1),
c(1,0,0,0,0,0),
c(0,0,1,1,0,1),
c(1,1,1,0,0,0)),
ncol = 5, nrow = 6)))
#derive topic cooccurrence matrix
cooccurrence_matrix <- get_cooccurrence_matrix(df)
#get list of topics
names(cooccurrence_matrix)
#print how many times topic "2" cooccurred with topic "3"
print(cooccurrence_matrix["2","3"])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.