Unwhich: Inverse Which

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

View source: R/DescTools.r

Description

The inverse function to which creates a logical vector/matrix from indices.

Usage

1
Unwhich(idx, n, useNames = TRUE)

Arguments

idx

the indices as returned by which.

n

integer, the length of the original vector.

useNames

logical, determining if the names of the indices should be preserved.

Value

a logical vector of the length n, with TRUE on the positions i.

Author(s)

Nick Sabbe

References

https://stackoverflow.com/questions/7659833/inverse-of-which

See Also

which

Examples

1
2
3
4
5
ll <- c(TRUE, FALSE, TRUE, NA, FALSE, FALSE, TRUE)
names(ll) <- letters[seq(ll)]
i <- which(ll)
# back again (loosing the names of the FALSEs)
Unwhich(i, length(ll))

DescTools documentation built on June 17, 2021, 5:12 p.m.