Indexing a Matrix or Data Frame According to Given Indices

indexData(x, indices)

Arguments

x

A matrix or data.frame (most useful for the latter).

indices

vector of column indices of x (typically obtained from zenpath()).

Value

An object as x

(typically a data.frame or

matrix) containing x

indexed by indices.

Note

Useful for constructing data.frames without .1, .2, ... in their names when indexing a data.frame with a zenpath.

See also

zenplot() which provides the zenplot.

Other tools related to constructing zenpaths: connect_pairs(), extract_pairs(), graph_pairs(), groupData(), zenpath()

Author

Marius Hofert and Wayne Oldford

Examples

## The function is handiest for data frames
## where we want to reuse the variable names
## without adding a suffix like ".1" etc.
## For example,
x <-  BOD  # Biochemical Oxygen Demand data in base R
indices <- rep(1:2, 2)
## now compare
indexData(x, indices)
#>   Time demand Time demand
#> 1    1    8.3    1    8.3
#> 2    2   10.3    2   10.3
#> 3    3   19.0    3   19.0
#> 4    4   16.0    4   16.0
#> 5    5   15.6    5   15.6
#> 6    7   19.8    7   19.8
## to
x[, indices]
#>   Time demand Time.1 demand.1
#> 1    1    8.3      1      8.3
#> 2    2   10.3      2     10.3
#> 3    3   19.0      3     19.0
#> 4    4   16.0      4     16.0
#> 5    5   15.6      5     15.6
#> 6    7   19.8      7     19.8
## zenplots prefer not to have the suffixes.