Skip to contents

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 'solute_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 method for class 'generic_spct'
x[i, j] <- value

# S3 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.

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.

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.

Note

If any argument is passed to j, even TRUE, some metadata attributes are removed from the returned object. This is how the extraction operator works with data.frames in R. For the time being we retain this behaviour for spectra, but it may change in the future.

See also

Examples

sun.spct[sun.spct[["w.length"]] > 400, ]
#> Object: source_spct [400 x 3]
#> Wavelength range 401-800 nm, step 1 nm 
#> Label: sunlight, simulated 
#> Measured on 2010-06-22 09:51:00 UTC 
#> Measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI 
#> Variables:
#>  w.length: Wavelength [nm]
#>  s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#>  s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1] 
#> --
#> # A tibble: 400 × 3
#>    w.length s.e.irrad  s.q.irrad
#>       <dbl>     <dbl>      <dbl>
#>  1      401     0.626 0.00000210
#>  2      402     0.650 0.00000218
#>  3      403     0.621 0.00000209
#>  4      404     0.637 0.00000215
#>  5      405     0.626 0.00000212
#>  6      406     0.600 0.00000204
#>  7      407     0.595 0.00000202
#>  8      408     0.626 0.00000213
#>  9      409     0.662 0.00000226
#> 10      410     0.561 0.00000192
#> # ℹ 390 more rows
subset(sun.spct, w.length > 400)
#> Object: source_spct [400 x 3]
#> Wavelength range 401-800 nm, step 1 nm 
#> Label: sunlight, simulated 
#> Measured on 2010-06-22 09:51:00 UTC 
#> Measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI 
#> Variables:
#>  w.length: Wavelength [nm]
#>  s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#>  s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1] 
#> --
#> # A tibble: 400 × 3
#>    w.length s.e.irrad  s.q.irrad
#>       <dbl>     <dbl>      <dbl>
#>  1      401     0.626 0.00000210
#>  2      402     0.650 0.00000218
#>  3      403     0.621 0.00000209
#>  4      404     0.637 0.00000215
#>  5      405     0.626 0.00000212
#>  6      406     0.600 0.00000204
#>  7      407     0.595 0.00000202
#>  8      408     0.626 0.00000213
#>  9      409     0.662 0.00000226
#> 10      410     0.561 0.00000192
#> # ℹ 390 more rows

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!
#> Object: source_spct [522 x 3]
#> Wavelength range 280-800 nm, step 0.9230769-1 nm 
#> Label: sunlight, simulated 
#> Measured on 2010-06-22 09:51:00 UTC 
#> Measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI 
#> Variables:
#>  w.length: Wavelength [nm]
#>  s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#>  s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1] 
#> --
#> # A tibble: 522 × 3
#>    w.length s.e.irrad s.q.irrad
#>       <dbl>     <dbl>     <dbl>
#>  1     280          0         0
#>  2     281.         0         0
#>  3     282.         0         0
#>  4     283.         0         0
#>  5     284.         0         0
#>  6     285.         0         0
#>  7     286.         0         0
#>  8     286.         0         0
#>  9     287.         0         0
#> 10     288.         0         0
#> # ℹ 512 more rows