R: Extract or replace parts of a spectrum

Extract {photobiology} | R Documentation

## Extract or replace parts of a spectrum

### Description

Just like extraction and replacement with indexes in base R, but preserving the special attributes used in spectral classes and checking for validity of remaining spectral data.

### Usage

    ## S3 method for class 'generic_spct'
    x[i, j, drop = NULL]

    ## S3 method for class 'raw_spct'
    x[i, j, drop = NULL]

    ## S3 method for class 'cps_spct'
    x[i, j, drop = NULL]

    ## S3 method for class 'source_spct'
    x[i, j, drop = NULL]

    ## S3 method for class 'response_spct'
    x[i, j, drop = NULL]

    ## S3 method for class 'filter_spct'
    x[i, j, drop = NULL]

    ## S3 method for class 'reflector_spct'
    x[i, j, drop = NULL]

    ## S3 method for class 'object_spct'
    x[i, j, drop = NULL]

    ## S3 method for class 'chroma_spct'
    x[i, j, drop = NULL]

    ## S3 replacement method for class 'generic_spct'
    x[i, j] <- value

    ## S3 replacement method for class 'generic_spct'
    x$name <- value

### Arguments

`x` | spectral object from which to extract element(s) or in which to replace element(s)
`i` | index for rows,
`j` | index for columns, specifying elements to extract or replace. Indices are numeric or character vectors or empty (missing) or NULL. Please, see `Extract` for more details.
`drop` | logical. If TRUE the result is coerced to the lowest possible dimension. The default is FALSE unless the result is a single column.
`value` | A suitable replacement value: it will be repeated a whole number of times if necessary and it may be coerced: see the Coercion section. If NULL, deletes the column if a single column is selected.
`name` | A literal character string or a name (possibly backtick quoted). For extraction, this is normally (see under ‘Environments’) partially matched to the names of the object.

### Details

These methods are just wrappers on the method for data.frame objects which copy the additional attributes used by these classes, and validate the extracted object as a spectral object. When drop is TRUE and the returned object has only one column, then a vector is returned. If the extracted columns are more than one but do not include `w.length`, a data frame is returned instead of a spectral object.

### Value

An object of the same class as `x` but containing only the subset of rows and columns that are selected. See details for special cases.

### See Also

`subset` and `trim_spct`

### Examples

    sun.spct[sun.spct$w.length > 400, ]
    subset(sun.spct, w.length > 400)

    tmp.spct <- sun.spct
    tmp.spct[tmp.spct$s.e.irrad < 1e-5 , "s.e.irrad"] <- 0
    e2q(tmp.spct[ , c("w.length", "s.e.irrad")]) # restore data consistency!

[Package photobiology version 0.9.21 Index]