subsetting {compositions} | R Documentation |

## Subsetting of compositions

### Description

Extract subsets (rows) or subsompositions (columns) of a compositional data set

### Usage

```
getStickyClassOption()
setStickyClassOption(value)
## S3 method for class 'acomp'
x[i, j, drop=gsi.LengthOne(j)]
## S3 method for class 'rcomp'
x[i, j, drop=gsi.LengthOne(j)]
## S3 method for class 'aplus'
x[i, j, drop=gsi.LengthOne(j)]
## S3 method for class 'rplus'
x[i, j, drop=gsi.LengthOne(j)]
## S3 method for class 'ccomp'
x[i, j, drop=gsi.LengthOne(j)]
## S3 method for class 'rmult'
x[i, j, drop=gsi.LengthOne(j)]
## S3 method for class 'acomp'
x$name
## S3 method for class 'rcomp'
x$name
## S3 method for class 'aplus'
x$name
## S3 method for class 'rplus'
x$name
## S3 method for class 'ccomp'
x$name
## S3 method for class 'rmult'
x$name
```

### Arguments

`x` |
vector or dataset of a compositions class |

`i` |
row indices/names to select/exclude, resp. boolean of fitting length (recyling appplied if length(i)<nrow(x)); if x is a compositional vector, this gives the elements (equivalent to variables) to be extracted/selected |

`j` |
column indices/names to select/exclude, resp. boolean of fitting length (recyling appplied if length(i)<ncol(x)) |

`drop` |
boolean, should matrices be simplified to vectors? defaults to FALSE (a difference with standard R). If set to TRUE, it has the extra effect of removing the compositional class |

`name` |
column name of the variable to be extracted OR name of a scaling function to be applied. It accepts |

`value` |
logical, controlling the global options for sticky classes |

### Value

For `[`

a vector or matrix with the relevant elements selected.
When selecting rows, this object is of the same class than `x`

, i.e. the class is sticky.
When selecting columns, the class depends on the number of columns selected and the value of `drop`

. With `drop=T`

, output is always a matrix or a vector. The same happens if
`gsi.LengthOne(j)==TRUE`

, which happens if and only if `j`

is a non-null vector of
length one (i.e. if you only want one single column).

If you want to get rid of sticky classes and return to the behaviour of "compositions" v1.xx, call `setStickyClassOption(FALSE)`

. This may be a good idea if you run old scripts written for that versions of "compositions". You can recover the default behaviour from "compositions" v2 with `setStickyClassOption(TRUE)`

, and check which sticky class status is currently defined in the global options with `getStickyClassOption()`

.

For `$`

the output is either a transformed data set of the appropriate class, or the selected column as a class-less vector. The transformation ability is particularly useful if you have put a whole compositional class into one column of a data set, in which case you can confortably use the transformations in formula interfaces (see example below). This is NEVER sticky.

### Author(s)

R. Tolosana-Delgado

### See Also

`rmult`

, `acomp`

, `rcomp`

,
`aplus`

,
`rplus`

, `ccomp`

,

### Examples

```
data(Hydrochem)
xc = acomp(Hydrochem[,6:10])
xc[1:3,]
xc[-(10:nrow(xc)),]
xc[1:3,1:3]
xc[1:3,1:3, drop=TRUE]
xc[1:3,1]
class(xc[1:4,1])
class(xc[1:4,1, drop=TRUE])
data("Hydrochem")
xc = acomp(Hydrochem[, 9:14])
Hydrochem$compo = xc
lm(compo$clr~River, data=Hydrochem)
```

*compositions*version 2.0-8 Index]