indnv

Purpose

Checks one numeric vector against another and returns the indices of the elements of the first vector in the second vector.

Format

z = indnv(needle, haystack)
Parameters
  • needle (Nx1 numeric vector) – contains the values to be found in vector haystack

  • haystack (Mx1 numeric vector) – searched for matches to the values in needle

Returns

z (Nx1 vector of integers) – the indices of the corresponding elements of needle in haystack.

Examples

// What elements to look for
needle = { 8, 7, 3 };

// Vector to look in
haystack = { 2, 7, 8, 4, 3 };

// Find locations of needle in haystack
z = indnv(needle, haystack);
    3
z = 2
    5

Remarks

If no matches are found for any of the elements in needle, then those elements in the returned vector are set to the GAUSS missing value code.

If there are duplicate elements in haystack, the index of the first match will be returned.

See also

Functions contains(), ismember(), rowcontains()