A simple class for indexed data.
indexed(x, i, ...)An atomic vector or data.frame.
An optional vector of indices (dafaults to 1:n, where
n is the number of elements in x).
Other arguments passed to methods.
An object identical to x but with the additional class
indexed and a indices attribute.
x <- c(3.7, 3.3, 3.5, 2.8)
y <- c(1, 2, 1, 2)
z <- indexed(x=x)
indices(z)
#> [1] 1 2 3 4
indices(z[2:3]) # Indices are preserved
#> [1] 2 3
d <- indexed(
data.frame(
x=x,
y=y
)
)
indices(d)
#> [1] 1 2 3 4
indices(d[[1]])
#> [1] 1 2 3 4
indices(d$x)
#> [1] 1 2 3 4
indices(subset(d, y==1))
#> [1] 1 3
lapply(split(d, d$y), indices)
#> $`1`
#> [1] 1 3
#>
#> $`2`
#> [1] 2 4
#>