well, there are different flavors to this problem:

1) If you're only interested in integer values and in testing if all values
of A appear in B, you can do the following:

A = seq(3,4)
B = seq(2,11)
N = min(nrow(A),nrow(B))
M = min(max(A),max(B))
I1 = table(A,1,M,1)!=0;
I2 = table(B,1,M,1)!=0;
ret = sum(I1==I2) == N;
print(ret);

2) If you are interested in testing if the sequence of values in A appears
in B, then this is a classic sequence alignment problem and, if I remember
correctly, there are good dynamic programming algorithms for that. However,
in a semi-vectorized form in DML, you could still do the following (which
first determines the set of equal start values and subsequently probes only
matching candidate subsequences):

A = seq(3,4)
B = seq(2,11)
N = min(nrow(A),nrow(B))
I = (B == A[1,]) * seq(1,nrow(B));
S = removeEmpty(target=I, margin="rows");
ret = FALSE;
if( sum(S) > 0 ) {
  for(i in 1:nrow(S)) {
    start = as.scalar(S[i,]);
    ret = ret | (sum(B[start:start+N-1,]==A)==N)
  }
}
print(ret);

Regards,
Matthias

On Sun, Jul 9, 2017 at 3:08 AM, arijit chakraborty <ak...@hotmail.com>
wrote:

> Hi,
>
>
> Suppose I've 2 vectors as
>
>
> A = matrix("2 3", 2, 1)
>
>
> B = matrix(seq(1, 10), 10, 1)
>
>
> And I want to check if A is in B or not. I can use a for-loop to do so.
> But in my case that's not efficient. Is there a way to solve this problem.
>
>
> I tried "in" as we do in R, but it's not working.
>
>
> Thank you!
>
> Arijit
>

Reply via email to