Learn R Programming

bazar (version 1.0.11)

unwhich: Quasi-inverse of the 'which' function

Description

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

Usage

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

Run this code
# NOT RUN {
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

# }

Run the code above in your browser using DataLab