sub-.fData {roahd} | R Documentation |
Operator sub-.fData
to subset fData
objects
Description
This method provides an easy and natural way to subset a functional dataset
stored in a fData
object, without having to deal with the inner
representation of fData
class.
Usage
## S3 method for class 'fData'
fD[i, j, as_fData = TRUE]
Arguments
fD |
the univariate functional dataset in form of |
i |
a valid expression to subset rows ( observations ) of the univariate functional dataset. |
j |
a valid expression to subset columns ( measurements over the grid ) of the univariate functional dataset (must be contiguous). |
as_fData |
logical flag to specify whether the output should be returned
as an |
Value
The method returns either an fData
object ( if as_fData
= TRUE
) or a matrix
( if as_fData = FALSE
) containing the
required subset ( both in terms of observations and measurement points ) of
the univariate functional dataset.
See Also
Examples
N = 20
P = 1e2
# One dimensional grid
grid = seq( 0, 1, length.out = P )
# Generating an exponential covariance function (see related help for more
# information )
C = exp_cov_function( grid, alpha = 0.3, beta = 0.4 )
# Generating a synthetic dataset with a gaussian distribution and
# required mean and covariance function:
fD = fData( grid,
generate_gauss_fdata( N,
centerline = sin( 2 * pi * grid ),
Cov = C ) )
dev.new()
oldpar <- par(mfrow = c(1, 1))
par(mfrow = c(2, 2))
# Original data
plot(fD)
# Subsetting observations
plot(fD[c(1, 2, 3), , as_fData = TRUE])
# Subsetting measurements
plot(fD[, 1:30])
# Subsetting both observations and measurements
plot(fD[1:10, 50:P])
par(oldpar)
# Subsetting both observations and measurements but returning a matrix
fD[1:10, 50:P, as_fData = FALSE]