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.

# S3 method for 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

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]
#>              [,1]        [,2]         [,3]        [,4]       [,5]        [,6]
#>  [1,]  0.15571023  0.05394313 -0.010780849 -0.09063739 -0.1143512 -0.14523890
#>  [2,]  0.10959388  0.05012043  0.003478128 -0.06194323 -0.2044141 -0.22585421
#>  [3,]  0.29252822  0.29485486  0.244233641  0.16760219  0.1585016  0.09157689
#>  [4,]  0.03368739 -0.02866872 -0.132115990 -0.15845305 -0.2688254 -0.27145879
#>  [5,] -0.72589877 -0.78463557 -0.893337883 -0.99894934 -1.0554206 -1.06384646
#>  [6,]  0.63410102  0.53840611  0.487731788  0.37984814  0.3999540  0.30555036
#>  [7,] -0.73617583 -0.74122573 -0.687828361 -0.68869309 -0.7213940 -0.68918202
#>  [8,] -0.63605890 -0.67265888 -0.735321465 -0.78644637 -0.8215378 -0.85313326
#>  [9,]  0.55989287  0.40086598  0.305341403  0.32381335  0.2945019  0.22169795
#> [10,]  0.88986599  0.78981635  0.629275816  0.58986158  0.5310359  0.47546561
#>              [,7]       [,8]        [,9]       [,10]       [,11]       [,12]
#>  [1,] -0.17986612 -0.1836741 -0.25703637 -0.30192277 -0.42249206 -0.48753353
#>  [2,] -0.33125824 -0.4255611 -0.42602172 -0.45878128 -0.61296910 -0.71285275
#>  [3,] -0.06572886 -0.1581716 -0.20332189 -0.23094640 -0.30606894 -0.34289153
#>  [4,] -0.28444268 -0.2797412 -0.30855196 -0.37436154 -0.36851026 -0.36618345
#>  [5,] -1.22930532 -1.3542589 -1.42269704 -1.39809440 -1.40619384 -1.51025348
#>  [6,]  0.20632515  0.1289454 -0.01494324 -0.04200449 -0.09355825 -0.21394900
#>  [7,] -0.66539314 -0.6634652 -0.75036353 -0.74451824 -0.73747386 -0.81958923
#>  [8,] -0.86051187 -0.9194232 -0.99319061 -1.02381984 -1.07564261 -1.20182695
#>  [9,]  0.26008300  0.1035773  0.03740319 -0.03599437 -0.09394831 -0.08825951
#> [10,]  0.36754547  0.3358160  0.30812476  0.26598981  0.17720486  0.19959598
#>            [,13]        [,14]       [,15]       [,16]       [,17]       [,18]
#>  [1,] -0.5133591 -0.630192222 -0.65851480 -0.65510530 -0.71840176 -0.81608375
#>  [2,] -0.7756104 -0.753537486 -0.74852706 -0.75745953 -0.73115692 -0.76811303
#>  [3,] -0.3122960 -0.446221809 -0.48520757 -0.54469703 -0.60157495 -0.59789548
#>  [4,] -0.3891691 -0.497853831 -0.50651021 -0.56437524 -0.68427094 -0.64589172
#>  [5,] -1.5022902 -1.627062106 -1.61387352 -1.68738108 -1.77561512 -1.84752959
#>  [6,] -0.2814990 -0.299971061 -0.34203904 -0.42510860 -0.47917483 -0.39161632
#>  [7,] -0.8871774 -0.993760982 -1.05444198 -0.99314597 -1.06972220 -1.08217793
#>  [8,] -1.1668158 -1.237787193 -1.22904552 -1.31359653 -1.36772752 -1.30572300
#>  [9,] -0.1161787 -0.129248080 -0.07817492  0.04543291  0.07370562 -0.04305017
#> [10,]  0.1080706 -0.005633225 -0.05882014 -0.05080198 -0.17602068 -0.21207974
#>             [,19]      [,20]       [,21]       [,22]       [,23]      [,24]
#>  [1,] -0.88980111 -0.9072469 -0.92240828 -1.01807466 -1.13381041 -1.0601972
#>  [2,] -0.76114272 -0.7572688 -0.77613593 -0.76448480 -0.78711425 -0.8946792
#>  [3,] -0.67083855 -0.7008982 -0.73560646 -0.80459896 -0.84341471 -0.9340490
#>  [4,] -0.67084720 -0.6549467 -0.70798876 -0.82314305 -0.94120118 -0.9517486
#>  [5,] -1.77001255 -1.8532956 -1.80171225 -1.81345978 -1.86041464 -1.9092946
#>  [6,] -0.44474641 -0.4471863 -0.47297307 -0.48046249 -0.52734727 -0.6171718
#>  [7,] -1.10439939 -1.1676846 -1.24280789 -1.33205892 -1.40263764 -1.4523703
#>  [8,] -1.28433555 -1.3463400 -1.29600866 -1.35831553 -1.42813646 -1.3943454
#>  [9,] -0.08593167 -0.1473243 -0.05443607 -0.06435253 -0.09531662 -0.1424377
#> [10,] -0.22632123 -0.2294188 -0.26389508 -0.26761045 -0.40262268 -0.3623419
#>             [,25]      [,26]      [,27]      [,28]      [,29]      [,30]
#>  [1,] -1.18405540 -1.1309468 -1.0992055 -1.0466398 -0.9496997 -0.9838154
#>  [2,] -0.88105958 -0.9210664 -0.9871318 -0.9745971 -0.8877368 -0.8604692
#>  [3,] -0.93456632 -0.8887388 -0.9003804 -0.8465692 -0.7550010 -0.7288031
#>  [4,] -0.92810467 -1.0188469 -0.9703217 -0.9623379 -0.9248397 -0.8427041
#>  [5,] -1.88074024 -1.9592467 -1.9539745 -1.9227642 -1.9255733 -1.8548590
#>  [6,] -0.56504937 -0.5366932 -0.5192165 -0.5595405 -0.4958376 -0.3818139
#>  [7,] -1.45826866 -1.4574216 -1.4475058 -1.4068683 -1.3920492 -1.3343258
#>  [8,] -1.37125854 -1.3599326 -1.3125807 -1.2682059 -1.3053251 -1.2336065
#>  [9,] -0.05838866 -0.1094303 -0.1230337 -0.1797825 -0.2066152 -0.1523425
#> [10,] -0.39096298 -0.3438674 -0.3608830 -0.2972155 -0.3125300 -0.1975657
#>            [,31]       [,32]       [,33]       [,34]        [,35]        [,36]
#>  [1,] -1.0061895 -1.06384474 -1.01443471 -0.97935209 -0.933444546 -0.864977686
#>  [2,] -0.8055987 -0.76466679 -0.60564975 -0.60789422 -0.607659885 -0.565718818
#>  [3,] -0.6787448 -0.63234900 -0.71317046 -0.66111242 -0.696497620 -0.654068172
#>  [4,] -0.7551775 -0.79669531 -0.82124731 -0.89308912 -0.915851331 -0.935332957
#>  [5,] -1.8096618 -1.80219606 -1.71797884 -1.73322553 -1.666634484 -1.639708807
#>  [6,] -0.3968755 -0.40107110 -0.49724104 -0.39075809 -0.384284371 -0.413408613
#>  [7,] -1.2475907 -1.29635462 -1.26993372 -1.21294310 -1.187046720 -1.196994268
#>  [8,] -1.1741881 -1.15440913 -1.06441442 -1.12771301 -1.070905088 -0.995962380
#>  [9,] -0.1013394 -0.06007813 -0.07960923 -0.06581650 -0.005081894 -0.001925954
#> [10,] -0.1965540 -0.18349359 -0.13669756 -0.09506957 -0.078341059  0.038237911
#>             [,37]       [,38]       [,39]       [,40]       [,41]        [,42]
#>  [1,] -0.80024952 -0.75363927 -0.69217139 -0.57449114 -0.59346485 -0.521636890
#>  [2,] -0.54895054 -0.43472601 -0.46263091 -0.41380674 -0.33134180 -0.300555466
#>  [3,] -0.62629727 -0.57705035 -0.53855858 -0.51938025 -0.45048793 -0.452542660
#>  [4,] -0.90551532 -0.86398398 -0.82734123 -0.72218463 -0.61824868 -0.543097833
#>  [5,] -1.58997600 -1.51977639 -1.45068824 -1.53826693 -1.61390641 -1.496208847
#>  [6,] -0.36181581 -0.29639397 -0.28719569 -0.24924469 -0.24340629 -0.213927909
#>  [7,] -1.08989632 -1.18734579 -1.12627713 -1.11676679 -1.10891041 -1.048287852
#>  [8,] -0.98434038 -0.95969222 -0.90873345 -0.86706191 -0.77288197 -0.643802092
#>  [9,]  0.06664477  0.16068434  0.16342510  0.17586069  0.20422785  0.275560510
#> [10,]  0.06122969  0.09097366  0.03484126  0.01728403  0.02766893  0.008614858
#>             [,43]       [,44]       [,45]       [,46]       [,47]       [,48]
#>  [1,] -0.32767517 -0.28816701 -0.28548739 -0.29179293 -0.17250635 -0.08584843
#>  [2,] -0.20894128 -0.19464080 -0.13714677 -0.07306644  0.06864796  0.06068906
#>  [3,] -0.38679222 -0.32968612 -0.20862188 -0.15104090 -0.08415585  0.04885274
#>  [4,] -0.45194043 -0.40623305 -0.42816530 -0.45371412 -0.33216897 -0.24332894
#>  [5,] -1.42123826 -1.32696989 -1.31334608 -1.20311595 -1.15898824 -1.14845418
#>  [6,] -0.14192794 -0.06231431 -0.09780012 -0.02908872  0.07810174  0.16305166
#>  [7,] -1.03402201 -0.92972969 -0.82993197 -0.71801901 -0.74532590 -0.63252434
#>  [8,] -0.58581246 -0.47921144 -0.38853352 -0.42221877 -0.28792560 -0.25465820
#>  [9,]  0.34759303  0.37119756  0.45003801  0.51139124  0.60641888  0.59302856
#> [10,]  0.07626148  0.11322746  0.12169808  0.17399686  0.26506773  0.33962074
#>             [,49]      [,50]       [,51]
#>  [1,] -0.10781276 -0.1213875 -0.09375163
#>  [2,]  0.12136523  0.1532780  0.19152294
#>  [3,]  0.06450932  0.1153795  0.16888232
#>  [4,] -0.15560227 -0.1527559 -0.13639446
#>  [5,] -1.12778994 -1.0337334 -0.93399027
#>  [6,]  0.19984692  0.3190096  0.44391998
#>  [7,] -0.68303759 -0.6050737 -0.53211826
#>  [8,] -0.22082312 -0.0897822 -0.12239599
#>  [9,]  0.67858355  0.7256001  0.84758525
#> [10,]  0.41219420  0.3092243  0.33324240