![](`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]]
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.