Learn R Programming

compositions (version 2.0-0)

subsetting: Subsetting of compositions

Description

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

Usage

getStickyClassOption()
  setStickyClassOption(value)
# S3 method for acomp
[(x, i, j, drop=gsi.LengthOne(j))
# S3 method for rcomp
[(x, i, j, drop=gsi.LengthOne(j))
# S3 method for aplus
[(x, i, j, drop=gsi.LengthOne(j))
# S3 method for rplus
[(x, i, j, drop=gsi.LengthOne(j))
# S3 method for ccomp
[(x, i, j, drop=gsi.LengthOne(j))
# S3 method for rmult
[(x, i, j, drop=gsi.LengthOne(j))
# S3 method for acomp
$(x, name) 
# S3 method for rcomp
$(x, name)
# S3 method for aplus
$(x, name) 
# S3 method for rplus
$(x, name)
# S3 method for ccomp
$(x, name) 
# S3 method for 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 unclass (or raw), clo, pwlr, alr, clr, ilr, apt, cpt, ipt, iit, ilt, cdt, idt and their inverses *Inv

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.

See Also

rmult, acomp, rcomp, aplus, rplus, ccomp,

Examples

Run this code
# NOT RUN {
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)
# }

Run the code above in your browser using DataLab