1
$\begingroup$

I have a question about how to create a matrix that will take the lists defined below and make them the entries for the columns and rows. My data involves two lists: one lists originals sources (or papers) and the other lists those sources' individual citations.

The code is done in RStudio.

A sample of my original dataset looks like this:

enter image description here

 # List all the sources
 sources.vertices.levels <- cit.total$Sources
 sources.vertices <- (as.character(sources.vertices.levels))

 citation.edges.levels <- cit.total$Citations
 citation.edges <- (as.character(citation.edges.levels))

 # Break up the factors into character lists
 list.sources <- levels(sources.vertices.levels)
 list.citations <- levels(citation.edges.levels)

Below I have created an empty matrix (50X1497). I would like to make the row names be each individual source, and the columns be each individual citation.

Also I am lost on how to create a binary matrix that matches each individual source (from the rows) to the individual citations (to the columns).

 # Building an aggregate matrix
 matrix.network <- matrix(cit.citations,ncol=1497, nrow=50)

An example of what kind of matrix I want to do is below:

enter image description here

$\endgroup$
0
1
$\begingroup$

Are the 1s and 0s only to indicate that the source matches the citation? If so, try this :

library(tidyverse); library(magrittr)    
cit.total %>% 
mutate(score = 1) %>% # so that all 'matches' in your original data frame are tagged '1'
spread("Citations", "score", fill = 0) # each source and citation pair gets a number, 1 if the match exists, 0 if it doesn't
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.