invwhich: Convert indices to logical vector

Description Usage Arguments Value Changes Author(s) References See Also Examples

View source: R/invwhich.R

Description

Gives a logical vector which is TRUE for the indices provided

Usage

1
invwhich(ix, n = max(if (is.numeric(ix)) ix, length(nm)), nm)

Arguments

ix

an vector of indices

n

the length of the output vector; defaults to the maximum index

nm

(optional) names for the vector

Value

a logical vector of length n and names nm

If nm is specified, ix may be a character vector instead.

Changes

Rather than using a useNames logical to copy the names attribute from one vector to another, you may specify names via the nm argument.

Author(s)

Nick Sabbe, Neal Fultz

References

http://stackoverflow.com/a/7661128/986793

See Also

interaction

Examples

1
2
3
4
5
6
7
8
x <- rnorm(50) > 1
ix <- which(x)
all.equal(x, invwhich(ix, 50))

all.equal(
  invwhich(grep('O', state.abb), 50),
  grepl('O', state.abb)
)

stackoverflow documentation built on Jan. 10, 2020, 9:07 a.m.