Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First off, your data. Your output appears sonewhat strange. If this is not what you have, consider using <code>dput</code> to dump these variables in a reproducible way.</p> <pre><code>mtop &lt;- c("TUBA1A", "DNAJB1", "MME", "PRKCB", "PARK2|KB-152G3.1", "UBC") neighbors &lt;- list(c("CNBP", "IGF2BP1", "RPL3|OK/SW-cl.32", "HNRNPC", "PURA|hCG_45299", "RPS3A", "Cnbp", "Mis12|DN-393H17.5"), c("NIN", "PRKACA", "AURKA|RP5-1167H4.6", "GSK3B", "AMOT", "UBC")) </code></pre> <p>To select those elements of list <code>neighbors</code> which have at least one vector element in common with <code>mtop</code>, you can use this command:</p> <pre><code>matching &lt;- sapply(neighbors, function(l) length(intersect(mtop, l)) &gt; 0) print(neighbors[matching]) </code></pre> <p>This will print <code>neighbors[2]</code>, as it has <code>"UBC"</code> in common with <code>mtop</code>. It does this via the logical vector <code>matching</code>. Which seems to be what your question asked.</p> <p>If you want to take position into account, i.e. only select <code>neighbors[2]</code> because <code>"UBC"</code> is in position 6 in both vectors, then you should use this command:</p> <pre><code>matching &lt;- sapply(neighbors, function(l) any(l == mtop)) </code></pre> <p>However, this will create a warning, as <code>neighbors[[1]]</code> is longer than <code>mtop</code>.</p> <p>If you want the names common to both your data structures, you can use this code:</p> <pre><code>intersect(unlist(neighbors), mtop) </code></pre> <p>If you need something else, you have to be more specific in your question, i.e. give an explicit example of what the output should look like, and cover all the possible input configurations that might lead to structurally different output.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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