sub-.fData: Operator 'sub-.fData' to subset 'fData' objects

Description Usage Arguments Value See Also Examples

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

1
2
## S3 method for class 'fData'
fD[i, j, as_fData = TRUE]

Arguments

fD

the univariate functional dataset in form of fData object.

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 fData object containing the required subset or as a matrix of values, default is TRUE.

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

fData

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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]

roahd documentation built on Nov. 4, 2021, 1:07 a.m.