Learn R Programming

spatstat.utils (version 3.2-5)

positiveIndex: Convert Any Kind of Index to an Integer Vector.

Description

Converts any kind of index to an integer vector of indices.

Usage

positiveIndex(i, nama=NULL, len = length(nama))

Value

An integer vector.

Arguments

i

Any valid kind of index for a vector.

nama

Optional. Character vector of names for the vector being indexed.

len

Integer. Length of the vector being indexed.

Entries outside the range

Values in the argument i which imply a position outside the range from 1 to len are returned as NA.

Author

Adrian Baddeley Adrian.Baddeley@curtin.edu.au.

Details

This utility function interprets any kind of index for a vector and converts it to a positive integer index.

Suppose that x is a vector of length len with names names(x) = nama. Then R allows the vector x to be indexed as x[i] where i may be

  • a vector of positive integers between 1 and len specifying the elements to be included;

  • a vector of negative integers between -1 and -len specifying the elements to be omitted;

  • a logical vector of length len specifying whether each element of x is to be included (TRUE) or excluded (FALSE);

  • a character vector containing elements of nama identifying the elements to be included;

  • missing (equivalent to specifying all elements of x).

The function positiveIndex interprets any such index i and converts it to the first type of index (a vector of positive integers specifying the elements to be included).

If argument i is missing or NULL, it is interpreted as a missing index, and the result is the full sequence from 1 to len.

See Also

logicalIndex

Examples

Run this code
   positiveIndex(2:4, len=5)
   positiveIndex(-3, len=5)
   positiveIndex(letters[4:6], letters)
   positiveIndex(len=5)

Run the code above in your browser using DataLab