These methods are useful for dealing with NAs in e.g., source_spct
,
response_spct
, filter_spct
and reflector_spct
.
Usage
# S3 method for class 'generic_spct'
na.omit(object, na.action = "omit", fill = NULL, target.colnames, ...)
# S3 method for class 'source_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)
# S3 method for class 'response_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)
# S3 method for class 'filter_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)
# S3 method for class 'reflector_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)
# S3 method for class 'object_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)
# S3 method for class 'solute_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)
# S3 method for class 'cps_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)
# S3 method for class 'raw_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)
# S3 method for class 'chroma_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)
# S3 method for class 'generic_mspct'
na.omit(object, na.action = "omit", fill = NULL, ...)
# S3 method for class 'generic_spct'
na.exclude(object, na.action = "exclude", fill = NULL, target.colnames, ...)
# S3 method for class 'source_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)
# S3 method for class 'response_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)
# S3 method for class 'filter_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)
# S3 method for class 'reflector_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)
# S3 method for class 'object_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)
# S3 method for class 'solute_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)
# S3 method for class 'cps_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)
# S3 method for class 'raw_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)
# S3 method for class 'chroma_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)
# S3 method for class 'generic_mspct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)
Arguments
- object
an R object
- na.action
character One of "omit", "exclude" or "replace".
- fill
numeric Value used to replace NAs unless NULL, in which case interpolation is attempted.
- target.colnames
character Vector of names for the target columns to operate upon, if present in
object
.- ...
further arguments other special methods could require
Details
If na.omit
removes cases, the row numbers of the cases form
the "na.action"
attribute of the result, of class "omit"
.
na.exclude
differs from na.omit
only in the class of the
"na.action" attribute of the result, which is "exclude"
.
Note
na.fail
and na.pass
do not require a specialisation
for spectral objects. R's definitions work as expected with no need to
override them. We do not define a method na.replace
, just pass
"replace"
as argument. The current implementation replaces by
interpolation only individual NAs which are flanked on both sides by
valid data. Runs of multiple NAs con only replaced by a constant value
passed through parameter fill
.
Examples
my_sun.spct <- sun.spct
my_sun.spct[3, "s.e.irrad"] <- NA
my_sun.spct[5, "s.q.irrad"] <- NA
head(my_sun.spct)
#> Object: source_spct [6 x 3]
#> Wavelength range 280-284.61538 nm, step 0.9230769 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: 6 × 3
#> w.length s.e.irrad s.q.irrad
#> <dbl> <dbl> <dbl>
#> 1 280 0 0
#> 2 281. 0 0
#> 3 282. NA 0
#> 4 283. 0 0
#> 5 284. 0 NA
#> 6 285. 0 0
# rows omitted
zo <- na.omit(my_sun.spct)
head(zo)
#> Object: source_spct [6 x 3]
#> Wavelength range 280-286.46154 nm, step 0.9230769-1.846154 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: 6 × 3
#> w.length s.e.irrad s.q.irrad
#> <dbl> <dbl> <dbl>
#> 1 280 0 0
#> 2 281. 0 0
#> 3 283. 0 0
#> 4 285. 0 0
#> 5 286. 0 0
#> 6 286. 0 0
na.action(zo)
#> [1] 3 5
#> attr(,"class")
#> [1] "omit"
# rows excluded
ze <- na.exclude(my_sun.spct)
head(ze)
#> Object: source_spct [6 x 3]
#> Wavelength range 280-286.46154 nm, step 0.9230769-1.846154 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: 6 × 3
#> w.length s.e.irrad s.q.irrad
#> <dbl> <dbl> <dbl>
#> 1 280 0 0
#> 2 281. 0 0
#> 3 283. 0 0
#> 4 285. 0 0
#> 5 286. 0 0
#> 6 286. 0 0
na.action(ze)
#> [1] 3 5
#> attr(,"class")
#> [1] "exclude"
# data in both rows replaced
zr <- na.omit(my_sun.spct, na.action = "replace")
head(zr)
#> Object: source_spct [6 x 3]
#> Wavelength range 280-284.61538 nm, step 0.9230769 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: 6 × 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
na.action(zr)
#> [1] 3 5
#> attr(,"class")
#> [1] "replace"