unwhich: Quasi-inverse of the 'which' function

Description Usage Arguments Value See Also Examples

Description

The unwhich function is a kind of inverse of the which function.

Usage

1
unwhich(w, n)

Arguments

w

A vector of integers; morally the result of a call to which.

n

integer. The length of the result; morally the length of the x argument of a call to which.

Value

A logical vector of length n.

See Also

which.

Examples

1
2
3
4
5
6
7
x1 <- c(TRUE, FALSE, TRUE, TRUE)
x2 <- unwhich(which(x1), length(x1))
identical(x1, x2) # TRUE

w1 <- c(2, 4, 5, 1, 1)
w2 <- which(unwhich(w1, 10))
identical(sort(unique(as.integer(w1))), w2) # TRUE

bazar documentation built on May 2, 2019, 7:02 a.m.