Disordered indices with the `disordR` package: an introduction to class `disindex`

![](`r system.file("help/figures/disordR.png", package = "disordR")`){width=10%}

knitr::opts_chunk$set(echo = TRUE)

Experimental S4 class disindex allows extraction methods, including list extraction, to operate with the output of which(). Consider the following R session:

library("disordR")
(d <- disord(c(4,6,1,2,3,4,5,1)))
ind <- which(d>4)

Above, object ind points to those elements of d which exceed 4. Thus:

d
d[ind]
d[ind] <- 99
d

However, we cannot assert that ind is elements 2 and 7 of d, for the elements of d are stored in an implementation-specific order. If we examine ind directly, we see:

ind

which correctly says that the elements of ind are implementation-specific. However, the main application of disindex objects is for list extraction.

d <- disord(c(4,1,6,2))
dl <- sapply(d,function(x){seq(from=5,to=x)})
dl

Suppose I wish to extract from object dl just the element with the longest length. Noting that this would be a disord-compliant question, we would use:

howlong <- unlist(lapply(dl,length))
longest <- which(howlong == max(howlong))
dl[[longest]]


Try the disordR package in your browser

Any scripts or data that you put into this service are public.

disordR documentation built on May 29, 2024, 11:06 a.m.