title: R: How to match a value in a vector with all values in the same vector
body: <p>I am looking in a vector similar to this</p>
  
  <p>x &lt;- c("P1D3,P3A7", 0, 0, "P1D3,P3A7", "P1D3, P2A3, P4D2", 0, "P1D3, P3A7, P2G60", "P1D3,P3A7")</p>
  
  <p>I currently have it using grepl </p>
  
  <pre><code>xPres &lt;- grepl("P",x, ignore.case = FALSE)
  </code></pre>
  
  <p>Currently if I did</p>
  
  <pre><code>View(xPres)
  </code></pre>
  
  <p>I would see a vector like this</p>
  
  <p>(TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE)</p>
  
  <p>However, I don't just want to look for anything containing a value other than 0 in it, I want to be able to check to see if a value in a vector or a part of the value in the vector matches some other value or part of a value in the same vector.</p>
  
  <p>The ideal result would produce something like this</p>
  
  <p>(TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, TRUE)</p>
  
  <p>The 5th value would change because it does not have any part that is matching, whereas everything else has some part of it that is matching some other value in the same vector, including the 7th value because a portion of it is matching some other value. </p>
  
  <p>The only problem is that every value has "P1D3", because it is present in all of the samples. Is there a way to solve this problem?</p>
  
  <p>Edit: If I created a new vector with </p>
  
  <p>x &lt;- c("P1D3,P3A7", 0, 0, "P1D3,P3A7", "P1D3, P2A3, P4D2", 0, "P1D3, P3A7, P2G60", "P1D3,P3A7", "P1D3, P2A3, P4D2")</p>
  
  <p>the code should produce </p>
  
  <p>(TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE)</p>
  
  <p>It seems that finding multiple common substrings is the simplelest way to go, but I do not know the package to download or what to use.</p>