Learn R Programming

funData (version 1.2)

getArgvals: Extract and set slots from functional data objects

Description

These functions can be used to extract and set the slots of funData, irregFunData and multiFunData objects.

Usage

getArgvals(object)

getX(object)

setArgvals(object, newArgvals)

setX(object, newX)

Arguments

object

An object of class funData, irregFunData or multiFunData.

newArgvals

See Details.

newX

See Details.

Value

See Details.

Details

Objects of class funData or irregFunData have two slots, argvals (for the x-values) and X (for the y-values for each observation). Using the getArgvals and getX methods for the classes funData and irregFunData is equivalent to accessing the slots directly via object@argvals and object@X. Analogously, the setArgvals and setX functions are equivalent to setting object@argvals to newArgvals or object@X to newX, respectively. The new values must hence have the same structure as the original ones. As an exception, for an object of class funData the number of new observations in newX may differ from the current (e.g. when adding new observations). In this case, the function throws a warning.

Objects of class multiFunData are lists of several funData objects. The functions getArgvals and getX for multiFunData objects therefore return a list of the same length as object, where each list element corresponds to the argvals or X slot of the univariate element. The setArgvals and getArgvals functions for multiFunData objects must be lists of the same length as object, where each list element corresponds to the new argvals or new X slot for the univariate elements.

For all classes, the set functions do not change the object, unless their result is assigned to object (see Examples).

See Also

'>funData, '>irregFunData, '>multiFunData

Examples

Run this code
# NOT RUN {
### Univariate
object <- funData(argvals = 1:5, X = rbind(1:5, 6:10))
object

# get-methods
getArgvals(object)
getX(object)

# set-methods
setArgvals(object, 0:4)
object # no change
object <- setArgvals(object, 0:4) # reassign the result to object
object # now, argvals is changed
# }
# NOT RUN {
object <- setArgvals(object, 1:4)
# }
# NOT RUN {
 # wrong length
object <- setX(object, rbind(0:4, 5:9))
newObject <- setX(object, rbind(0:4, 5:9, 10:14)) # warning: now 3 observations (was 2 before)
# }
# NOT RUN {
object <- setX(object, rbind(1:4, 5:8))
# }
# NOT RUN {
 # wrong length

### Univariate (irregular)
irregObject <- irregFunData(argvals = list(1:5, 2:4), X = list(2:6, 3:5))
irregObject

# get-methods
getArgvals(irregObject)
getX(irregObject)

newIrregObject <- setArgvals(irregObject, list(0:4, 1:3))
newIrregObject <- setX(irregObject, list(12:16, 13:15))

### Multivariate
multiObject <- multiFunData(object, funData(argvals = 1:3, X = rbind(3:5, 6:8)))
multiObject

# get-methods
getArgvals(multiObject)
getX(multiObject)

# set-methods (for special cases see univariate version)
multiObject <- setArgvals(multiObject, list(5:1, 3:1))
multiObject <- setX(multiObject, list(rbind(5:1, 10:6), rbind(5:3, 8:6)))
# }

Run the code above in your browser using DataLab