Learn R Programming

spatstat.utils (version 3.2-5)

logicalIndex: Convert Any Kind of Index to a Logical Vector

Description

Converts any kind of index to an logical vector.

Usage

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

Value

A logical vector.

Arguments

i

Any 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 of i which imply a position outside the range from 1 to len are ignored. Values of i which are NA are also ignored.

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 logical vector.

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 logicalIndex interprets any such index i and converts it to a logical vector.

If argument i is missing or NULL, it is interpreted as a missing index, and the result is a vector of TRUE values.

See Also

positiveIndex

Examples

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

Run the code above in your browser using DataLab