Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

invwhich

Convert indices to logical vector


Description

Gives a logical vector which is TRUE for the indices provided

Usage

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

See Also

Examples

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

Stack Overflow's Greatest Hits

v0.7.0
CC BY-SA 4.0
Authors
Neal Fultz <nfultz@gmail.com> and the StackOverflow.com community
Initial release
2020-01-03

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.