Skip to contents

Operators acting on objects to extract or replace parts.

Usage

# S4 method for CompositionMatrix,missing,missing,missing
[(x, i, j, ..., drop = TRUE)

# S4 method for CompositionMatrix,missing,missing,logical
[(x, i, j, ..., drop = TRUE)

# S4 method for CompositionMatrix,index,missing,missing
[(x, i, j, ..., drop = TRUE)

# S4 method for CompositionMatrix,index,missing,logical
[(x, i, j, ..., drop = TRUE)

# S4 method for CompositionMatrix,missing,index,missing
[(x, i, j, ..., drop = TRUE)

# S4 method for CompositionMatrix,missing,index,logical
[(x, i, j, ..., drop = TRUE)

# S4 method for CompositionMatrix,index,index,missing
[(x, i, j, ..., drop = TRUE)

# S4 method for CompositionMatrix,index,index,logical
[(x, i, j, ..., drop = TRUE)

# S4 method for OutlierIndex,index,ANY
[[(x, i)

# S4 method for CompositionMatrix
[(x, i, j, ...) <- value

# S4 method for CompositionMatrix
[[(x, i, j, ...) <- value

Arguments

x

An object from which to extract element(s) or in which to replace element(s).

i, j

Indices specifying elements to extract or replace. Indices are numeric, integer or character vectors or empty (missing) or NULL. Numeric values are coerced to integer as by as.integer(). Character vectors will be matched to the name of the elements. An empty index (a comma separated blank) indicates that all entries in that dimension are selected.

...

Currently not used.

drop

A logical scalar: should the result be coerced to the lowest possible dimension? This only works for extracting elements, not for the replacement.

value

A possible value for the element(s) of x.

Value

A subsetted object of the same sort as x.

See also

Other mutators: groups, identifiers, samples, split(), totals

Author

N. Frerebeau

Examples

## Data from Aitchison 1986
data("hongite")

## Coerce to compositional data
coda <- as_composition(hongite)
head(coda)
#> <CompositionMatrix: 6 x 5>
#>        A     B     C     D     E
#> H1 0.488 0.317 0.038 0.064 0.093
#> H2 0.482 0.238 0.090 0.092 0.098
#> H3 0.370 0.091 0.342 0.095 0.102
#> H4 0.509 0.238 0.072 0.101 0.080
#> H5 0.442 0.383 0.029 0.077 0.069
#> H6 0.523 0.262 0.042 0.125 0.048

## Subset
coda[[1, 1]] # Get the first value
#> [1] 0.488
coda[1] # Get the first value
#> [1] 0.488
coda[, ] # Get all values
#> <CompositionMatrix: 25 x 5>
#>             A         B          C          D          E
#> H1  0.4880000 0.3170000 0.03800000 0.06400000 0.09300000
#> H2  0.4820000 0.2380000 0.09000000 0.09200000 0.09800000
#> H3  0.3700000 0.0910000 0.34200000 0.09500000 0.10200000
#> H4  0.5090000 0.2380000 0.07200000 0.10100000 0.08000000
#> H5  0.4420000 0.3830000 0.02900000 0.07700000 0.06900000
#> H6  0.5230000 0.2620000 0.04200000 0.12500000 0.04800000
#> H7  0.4460000 0.3300000 0.04600000 0.12200000 0.05600000
#> H8  0.3460000 0.0520000 0.42900000 0.09600000 0.07700000
#> H9  0.4120000 0.1170000 0.26700000 0.09600000 0.10800000
#> H10 0.4260000 0.4660000 0.00700000 0.05600000 0.04500000
#> H11 0.4990000 0.1950000 0.11400000 0.09500000 0.09700000
#> H12 0.4520000 0.3730000 0.02700000 0.05500000 0.09300000
#> H13 0.3270000 0.0850000 0.38900000 0.08000000 0.11900000
#> H14 0.4140000 0.1290000 0.23400000 0.15800000 0.06500000
#> H15 0.4620000 0.1750000 0.15800000 0.08300000 0.12200000
#> H16 0.3230000 0.0730000 0.40900000 0.12900000 0.06600000
#> H17 0.4320000 0.4430000 0.01000000 0.07800000 0.03700000
#> H18 0.4954955 0.3233233 0.03103103 0.08708709 0.06306306
#> H19 0.4230000 0.1580000 0.20400000 0.08300000 0.13200000
#> H20 0.4460000 0.1150000 0.23800000 0.11600000 0.08500000
#> H21 0.4580000 0.1660000 0.16800000 0.12000000 0.08800000
#> H22 0.4990000 0.2500000 0.06800000 0.10900000 0.07400000
#> H23 0.4860000 0.3400000 0.02500000 0.09400000 0.05500000
#> H24 0.4550000 0.1660000 0.17600000 0.09600000 0.10700000
#> H25 0.4590000 0.2490000 0.09700000 0.09800000 0.09700000
coda[1, , drop = FALSE] # Get the first row
#> <CompositionMatrix: 1 x 5>
#>        A     B     C     D     E
#> H1 0.488 0.317 0.038 0.064 0.093

## Subcomposition
subcoda <- coda[, 1:3, drop = FALSE] # Get the first three column
head(subcoda)
#> <CompositionMatrix: 6 x 3>
#>        A     B     C
#> H1 0.488 0.317 0.038
#> H2 0.482 0.238 0.090
#> H3 0.370 0.091 0.342
#> H4 0.509 0.238 0.072
#> H5 0.442 0.383 0.029
#> H6 0.523 0.262 0.042