Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Unfortunately , your question is not clear, so I will try to answer. </p> <p>If I understand you want :</p> <p>****Given a big and small matrix : Find the locations where they match?****</p> <h1>I regenerate your data</h1> <pre><code>library(network) N &lt;- 20 grants &lt;- data.frame( projectleader = sample(x=LETTERS[1:20],size=N,replace = TRUE), projectpartner = sample(x=LETTERS[1:20],size=N,replace = TRUE), year_grant = sample(x=0:5 ,size=N,replace = TRUE) +2000 ) head(grants) projectleader projectpartner year_grant 1 D K 2002 2 M M 2001 3 K L 2005 4 N Q 2002 5 G D 2003 6 I B 2004 </code></pre> <h1>Function to create the small matrix</h1> <pre><code>## adjency &lt;- function(year){ grants_00 &lt;- subset(grants, (year_grant==year), select = c(projectpartner, projectleader)) nw_00 &lt;- network(grants_00, matrix="edgelist", directed=TRUE) grants_00.adj &lt;- as.matrix(nw_00, matrix.type = "adjacency") as.data.frame(grants_00.adj) } </code></pre> <h1>use plyr to get a list for every year</h1> <pre><code>library(plyr) years &lt;- unique(grants$year_grant) years &lt;- years[order(years)] bigMatrix &lt;- llply(as.list(years),.fun=adjm) </code></pre> <h1>Create full matrix (<a href="https://stackoverflow.com/questions/10943338/extending-converting-a-sparse-matrix-into-a-larger-sparse-matrix">The answer</a>)</h1> <pre><code># create an empty matrix with NAs population &lt;- union(grants$projectpartner,grants$projectleader) population_size &lt;- length(population) full_matrix &lt;- matrix(rep(NA, population_size*population_size), nrow=population_size) rownames(full_matrix) &lt;- colnames(full_matrix) &lt;- population </code></pre> <h1>find the location where they match</h1> <pre><code>frn &lt;- as.matrix(bigMatrix[[1]]) tmp &lt;- match(rownames(frn), rownames(full_matrix)) tmp2 &lt;- match(colnames(frn), colnames(full_matrix)) # do a merge full_matrix[tmp,tmp2] &lt;- frn head(bigMatrix[[1]]) D I J K O Q S D 0 0 0 0 0 0 0 I 0 0 0 0 0 0 0 J 1 0 0 0 0 0 0 K 0 0 0 0 0 0 0 O 0 0 0 1 0 0 0 Q 0 1 0 0 0 0 0 </code></pre> <h1>the full matrix</h1> <pre><code> K M L Q D B E J C S O F G N I A H K 0 NA NA 0 0 NA NA 0 NA 0 0 NA NA NA 0 NA NA M NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA L NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA Q 0 NA NA 0 0 NA NA 0 NA 0 0 NA NA NA 1 NA NA D 0 NA NA 0 0 NA NA 0 NA 0 0 NA NA NA 0 NA NA B NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA E NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA J 0 NA NA 0 1 NA NA 0 NA 0 0 NA NA NA 0 NA NA C NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA S 0 NA NA 1 0 NA NA 0 NA 0 0 NA NA NA 0 NA NA O 1 NA NA 0 0 NA NA 0 NA 0 0 NA NA NA 0 NA NA F NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA G NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA N NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA I 0 NA NA 0 0 NA NA 0 NA 0 0 NA NA NA 0 NA NA A NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA H NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload