Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

extractObs

Extract observations of functional data


Description

This function extracts one or more observations and/or observations on a part of the domain from a funData, irregFunData or multiFunData object.

Usage

extractObs(
  object,
  obs = seq_len(nObs(object)),
  argvals = funData::argvals(object)
)

## S4 method for signature 'funData'
subset(x, obs = seq_len(nObs(x)), argvals = funData::argvals(x))

## S4 method for signature 'multiFunData'
subset(x, obs = seq_len(nObs(x)), argvals = funData::argvals(x))

## S4 method for signature 'irregFunData'
subset(x, obs = seq_len(nObs(x)), argvals = funData::argvals(x))

## S4 method for signature 'funData,ANY,missing,missing'
x[i, j, ..., drop = TRUE]

## S4 method for signature 'multiFunData,ANY,missing,missing'
x[i, j, ..., drop = TRUE]

## S4 method for signature 'irregFunData,ANY,missing,missing'
x[i = seq_len(nObs(x)), j, ..., drop = TRUE]

Arguments

object

An object of class funData, irregFunData or multiFunData.

obs

A numeric vector, giving the indices of the observations to extract (default: all observations).

argvals

The part of the domain to be extracted (default: the whole domain object@argvals). Must be a list or a numeric vector (only for one-dimensional domains, see also the definition of funData, multiFunData).

x

An object of class funData, irregFunData or multiFunData (for subset).

i

A numeric vector, giving the indices of the observations to extract when using x[i]. Defaults to all observations.

j, drop

not used

...

Used to pass further arguments to extractObs. Here only usable for argvals.

Details

In case of an irregFunData object, some functions may not have observation points in the given part of the domain. In this case, the functions are removed from the extracted dataset and a warning is thrown.

If only observations are to be extracted, the usual notation object[1:3] is equivalent to extractObs(object, obs = 1:3). This works only if the domain remains unchanged.

Value

An object of class funData, irregFunData or multiFunData containing the desired observations.

Functions

  • [,funData,ANY,missing,missing-method:

Warning

The function is currently implemented only for functional data with up to three-dimensional domains.

Alias

The function subset is an alias for extractObs.

See Also

Examples

# Univariate - one-dimensional domain
object1 <- funData(argvals = 1:5, X = rbind(1:5, 6:10))
extractObs(object1, obs = 1)
extractObs(object1, argvals = 1:3)
extractObs(object1, argvals = list(1:3)) # the same as the statement before
# alias
subset(object1, argvals = 1:3)

# Univariate - two-dimensional domains
object2 <- funData(argvals = list(1:5, 1:6), X = array(1:60, dim = c(2, 5, 6)))
extractObs(object2, obs = 1)
extractObs(object2, argvals = list(1:3, c(2,4,6))) # argvals must be supplied as list

# Univariate - irregular
irregObject <- irregFunData(argvals = list(1:5, 2:4), X = list(2:6, 3:5))
extractObs(irregObject, obs = 2)
extractObs(irregObject, argvals = 1:3)
extractObs(irregObject, argvals = c(1,5)) # throws a warning, as second function has no observations

# Multivariate
multiObject <- multiFunData(object1, object2)
extractObs(multiObject, obs = 2)
multiObject[2] # shorthand
extractObs(multiObject, argvals = list(1:3, list(1:3, c(2,4,6))))


### Shorthand via "[]"
object1[1]
object1[argvals = 1:3]
object2[1] 
object2[argvals = list(1:3, c(2,4,6))]
irregObject[2]
irregObject[argvals = 1:3]

funData

An S4 Class for Functional Data

v1.3-5
GPL-2
Authors
Clara Happ-Kurz [aut, cre]
Initial release
2020-04-23

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.