# subset: extract a subset of a colorSpec Object In colorSpec: Color Calculations with Emphasis on Spectral Data

## Description

extract a subset of the spectra in a colorSpec object.
The subset can be specified by indexes, by a logical vector, or by a regular expression matching the `specnames`

## Usage

 ```1 2``` ```## S3 method for class 'colorSpec' subset( x, subset, ... ) ```

## Arguments

 `x` a colorSpec object `subset` an integer vector, a logical vector, or a regular expression `...` additional arguments ignored

## Details

If `subset` is an integer vector, each integer must be between 1 and M, where M the number of spectra in `x`. No duplicates are allowed. The number of spectra returned is equal to `length(subset)`. It is OK for the `length` to be 0, in which case the function returns the empty subset.

If `subset` is a logical vector, its length must be equal to M. The number of spectra returned is equal to the number of `TRUE`s in `subset`.

If `subset` is a regular expression, the number of spectra returned is equal to the number of `specnames(x)` matched by the expression.

## Value

`subset(x)` returns a colorSpec object with the same `organization` as `x`. Exception: if the organization of `x` is `'vector'` and the subset is empty, then the returned object is a matrix with 0 columns.

## Note

`subset()` can also be used for re-ordering the spectra; just set argument `subset` to the desired permutation vector.

`organization`
 ```1 2 3``` ```tritanope = subset( lms2000.1nm, 1:2 ) # keep long and medium cone fundamentals, but drop the short sml2000.1nm = subset( lms2000.1nm, 3:1 ) # reorder from short to long ```