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

Unwhich(idx, n = max(idx), useNames = TRUE)

Arguments

idx

the indices as returned by which.

n

integer, the length of the original vector. This must not be less than max(idx), which is also the default.

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

Nick Sabbe

See also

Examples

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))
#>     a  <NA>     c  <NA>  <NA>  <NA>     g 
#>  TRUE FALSE  TRUE FALSE FALSE FALSE  TRUE