Skip to content

all occurences of an element in a vector

5 messages · Ista Zahn, carol white, Joshua Wiley +1 more

#
Hi Carol,

I'm not sure what a "sub-vector in a vector" is, but I think you might
be looking for ?grep

Best,
Ista
On Mon, May 21, 2012 at 9:20 AM, carol white <wht_crl at yahoo.com> wrote:
#
On Mon, May 21, 2012 at 7:33 AM, carol white <wht_crl at yahoo.com> wrote:
I am pretty sure grep() is helpful if you are using the appropriate
regular expression to search for.  Like Ista, I am not sure exactly
what your search criteria are.  The easiest I think would be to give
us some examples.  Say give three vectors and what the desired output
from your search is.

Josh

  
    
#
To convert this from the abstract to the real ...

In what sense does %in% return only the first occurrence of an element?
See:
[1] "n" "m" "m" "n" "n"
foo        
[1,] "1" "FALSE"
[2,] "n" "TRUE" 
[3,] "m" "TRUE" 
[4,] "e" "FALSE"
[5,] "m" "TRUE" 
[6,] "n" "TRUE" 
[7,] "n" "TRUE" 
[8,] "u" "FALSE"



It sure looks to me like %in% identifies all the occurrences of
[m,n] in [1,n,m,e,m,n,n,u]

Or did you mean [m,n] appearing next to each other in that order???