Extract or replace parts of an FLR Object

# S4 method for FLArray,ANY,ANY,ANY
[(x, i, j, k, l, m, n, ..., drop = FALSE)

# S4 method for FLArray,array,missing,missing
[(x, i)

# S4 method for FLArray,ANY,ANY,ANY
[(x, i, j, k, l, m, n, ...) <- value

# S4 method for FLArray,ANY,ANY,FLArray
[(x, i, j, k, l, m, n, ...) <- value

# S4 method for FLQuant
$(x, name)

# S4 method for FLQuantDistr,ANY,ANY,ANY
[(x, i, j, k, l, m, n)

# S4 method for FLQuantDistr,array,missing,missing
[(x, i)

# S4 method for FLPar,ANY,ANY,ANY
[(x, i, j, k, l, m, n, ..., drop = FALSE)

# S4 method for FLPar,array,missing,missing
[(x, i)

# S4 method for FLPar,ANY,ANY,ANY
[(x, i, j, k, l, m, n, ...) <- value

# S4 method for FLPar
$(x, name)

# S4 method for FLComp,ANY,ANY,ANY
[(x, i, j, k, l, m, n, ..., drop = FALSE)

# S4 method for FLComp,ANY,ANY,ANY
[(x, i, j, k, l, m, n, ...) <- value

# S4 method for FLStock,ANY,ANY,ANY
[(x, i, j, k, l, m, n, ..., drop = FALSE)

# S4 method for FLStock,ANY,ANY,FLStock
[(x, i, j, k, l, m, n, ...) <- value

# S4 method for FLI,ANY,ANY,ANY
[(x, i, j, k, l, m, n, ..., drop = FALSE)

# S4 method for predictModel,ANY,missing,ANY
[(x, i)

# S4 method for FLlst,ANY,missing
[[(x, i, j) <- value

# S4 method for FLlst
$(x, name) <- value

# S4 method for FLlst,ANY,missing,ANY
[(x, i, j) <- value

# S4 method for FLlst,ANY,missing,ANY
[(x, i, j, drop)

Arguments

x
object from which to extract or replace element(s)
i, j, k, l, m, n, ...
indices specifying elements to extract or replace.
drop
If 'TRUE' the result is coerced to the lowest possible dimension, and so might change class (e.g. drop='TRUE' on an FLQuant might return an array of less dimensions, a matrix or a vector.
value
An object of a similar or simpler class than 'x'.
name
See Extract for further details.

Details

Operators acting on FLQuant, FLCohort, FLPar, FLComp, and derived classes to extract or replace sections of an object.

Please note the differences between referencing sections of an object by position using values of class numeric, or by using dimnames of class character. See examples below.

All classes that are derived from FLComp (for example, FLStock and FLBiol) can be subset along the six dimensions of their FLQuant slots.

Classes that are derived from FLlst (for example, FLStocks and FLBiols) can be subset in a similar way to ordinary list objects.

'$' for the FLPar and FLQuant classes operate only along the first dimension ('params' or 'quant'), and are provided to be used specially in formulas.

Generic function

[x,i,j,drop]
[<-(x,i,j,value)
[[<-(x,i,j,value)
\$<-(x,name,value)

See also

Extract

Examples

flq <- FLQuant(rnorm(200), dimnames=list(age=0:4, year=1991:2000, season=1:4)) # Extracting by position... flq[1,]
#> An object of class "FLQuant" #> , , unit = unique, season = 1, area = unique #> #> year #> age 1991 1992 1993 1994 1995 1996 #> 0 0.0307889 0.6766602 -0.5405284 -0.3095935 1.7951221 0.0598843 #> year #> age 1997 1998 1999 2000 #> 0 0.8400353 0.3858582 -0.0802218 -0.5259815 #> #> , , unit = unique, season = 2, area = unique #> #> year #> age 1991 1992 1993 1994 1995 1996 #> 0 0.1169163 0.2851892 -0.4601525 0.8007313 -2.4000574 0.2367283 #> year #> age 1997 1998 1999 2000 #> 0 1.1657546 -0.9298408 0.4874132 0.9324465 #> #> , , unit = unique, season = 3, area = unique #> #> year #> age 1991 1992 1993 1994 1995 1996 #> 0 -0.8077798 1.3954494 -2.0576698 -1.6832780 1.1587197 0.4668494 #> year #> age 1997 1998 1999 2000 #> 0 0.4665304 1.4796630 -0.0071697 0.4146715 #> #> , , unit = unique, season = 4, area = unique #> #> year #> age 1991 1992 1993 1994 1995 1996 #> 0 -0.7909489 0.4344542 0.4539588 1.0157901 0.7339844 -1.4999525 #> year #> age 1997 1998 1999 2000 #> 0 0.2731848 1.0704768 0.8983289 -1.8249571 #> #> units: NA
flq[,1:5]
#> An object of class "FLQuant" #> , , unit = unique, season = 1, area = unique #> #> year #> age 1991 1992 1993 1994 1995 #> 0 0.0307889 0.6766602 -0.5405284 -0.3095935 1.7951221 #> 1 0.8683820 1.0965677 0.9631811 -0.3640824 2.1308595 #> 2 -0.5868564 -0.0054018 -0.7453091 -0.9776918 -0.6288574 #> 3 -0.2223422 1.2309434 -2.4370368 0.6573057 0.5478358 #> 4 -0.1392056 -0.1209512 1.2692526 -0.7918942 -1.0816732 #> #> , , unit = unique, season = 2, area = unique #> #> year #> age 1991 1992 1993 1994 1995 #> 0 0.1169163 0.2851892 -0.4601525 0.8007313 -2.4000574 #> 1 -0.4044483 -0.5954382 -0.8239034 -0.2384143 -0.3147488 #> 2 0.7285455 -0.9951180 0.1048494 0.0339915 -0.3489642 #> 3 -0.4691204 -0.1720538 0.0012183 -0.2617264 -0.7954684 #> 4 -1.6948621 0.5353710 -0.4515997 -0.2487327 0.6499336 #> #> , , unit = unique, season = 3, area = unique #> #> year #> age 1991 1992 1993 1994 1995 #> 0 -0.8077798 1.3954494 -2.0576698 -1.6832780 1.1587197 #> 1 -0.4489336 0.7535879 0.7170255 1.1883881 -0.1499829 #> 2 1.4260378 0.5593508 -0.6316115 -1.4538138 0.7754196 #> 3 -0.4512673 2.0800399 1.2651173 2.2468224 -2.0040210 #> 4 -0.1749845 0.2924207 0.1483972 0.6930216 -1.1027980 #> #> , , unit = unique, season = 4, area = unique #> #> year #> age 1991 1992 1993 1994 1995 #> 0 -0.7909489 0.4344542 0.4539588 1.0157901 0.7339844 #> 1 0.7174211 0.1878014 -1.0386883 0.0424709 -0.2552334 #> 2 -0.6412440 -0.9097625 0.5934559 0.0719632 -1.0729966 #> 3 -0.3480327 -0.8799690 0.6737462 0.2895000 0.0489001 #> 4 -0.0891892 -1.4514463 0.5938412 0.3316570 -0.2529969 #> #> units: NA
flq[1:2,,,c(1,3)]
#> An object of class "FLQuant" #> , , unit = unique, season = 1, area = unique #> #> year #> age 1991 1992 1993 1994 1995 1996 #> 0 0.0307889 0.6766602 -0.5405284 -0.3095935 1.7951221 0.0598843 #> 1 0.8683820 1.0965677 0.9631811 -0.3640824 2.1308595 0.5041320 #> year #> age 1997 1998 1999 2000 #> 0 0.8400353 0.3858582 -0.0802218 -0.5259815 #> 1 0.0746456 -1.2360464 -0.6223109 -0.4793830 #> #> , , unit = unique, season = 3, area = unique #> #> year #> age 1991 1992 1993 1994 1995 1996 #> 0 -0.8077798 1.3954494 -2.0576698 -1.6832780 1.1587197 0.4668494 #> 1 -0.4489336 0.7535879 0.7170255 1.1883881 -0.1499829 0.2954394 #> year #> age 1997 1998 1999 2000 #> 0 0.4665304 1.4796630 -0.0071697 0.4146715 #> 1 -1.5521054 -0.3508083 0.3033496 -1.7676570 #> #> units: NA
# ...by dimnames flq['0',]
#> An object of class "FLQuant" #> , , unit = unique, season = 1, area = unique #> #> year #> age 1991 1992 1993 1994 1995 1996 #> 0 0.0307889 0.6766602 -0.5405284 -0.3095935 1.7951221 0.0598843 #> year #> age 1997 1998 1999 2000 #> 0 0.8400353 0.3858582 -0.0802218 -0.5259815 #> #> , , unit = unique, season = 2, area = unique #> #> year #> age 1991 1992 1993 1994 1995 1996 #> 0 0.1169163 0.2851892 -0.4601525 0.8007313 -2.4000574 0.2367283 #> year #> age 1997 1998 1999 2000 #> 0 1.1657546 -0.9298408 0.4874132 0.9324465 #> #> , , unit = unique, season = 3, area = unique #> #> year #> age 1991 1992 1993 1994 1995 1996 #> 0 -0.8077798 1.3954494 -2.0576698 -1.6832780 1.1587197 0.4668494 #> year #> age 1997 1998 1999 2000 #> 0 0.4665304 1.4796630 -0.0071697 0.4146715 #> #> , , unit = unique, season = 4, area = unique #> #> year #> age 1991 1992 1993 1994 1995 1996 #> 0 -0.7909489 0.4344542 0.4539588 1.0157901 0.7339844 -1.4999525 #> year #> age 1997 1998 1999 2000 #> 0 0.2731848 1.0704768 0.8983289 -1.8249571 #> #> units: NA
flq[,'1991']
#> An object of class "FLQuant" #> , , unit = unique, season = 1, area = unique #> #> year #> age 1991 #> 0 0.030789 #> 1 0.868382 #> 2 -0.586856 #> 3 -0.222342 #> 4 -0.139206 #> #> , , unit = unique, season = 2, area = unique #> #> year #> age 1991 #> 0 0.116916 #> 1 -0.404448 #> 2 0.728546 #> 3 -0.469120 #> 4 -1.694862 #> #> , , unit = unique, season = 3, area = unique #> #> year #> age 1991 #> 0 -0.807780 #> 1 -0.448934 #> 2 1.426038 #> 3 -0.451267 #> 4 -0.174985 #> #> , , unit = unique, season = 4, area = unique #> #> year #> age 1991 #> 0 -0.790949 #> 1 0.717421 #> 2 -0.641244 #> 3 -0.348033 #> 4 -0.089189 #> #> units: NA
flq[,as.character(1991:1995),,'1']
#> An object of class "FLQuant" #> , , unit = unique, season = 1, area = unique #> #> year #> age 1991 1992 1993 1994 1995 #> 0 0.0307889 0.6766602 -0.5405284 -0.3095935 1.7951221 #> 1 0.8683820 1.0965677 0.9631811 -0.3640824 2.1308595 #> 2 -0.5868564 -0.0054018 -0.7453091 -0.9776918 -0.6288574 #> 3 -0.2223422 1.2309434 -2.4370368 0.6573057 0.5478358 #> 4 -0.1392056 -0.1209512 1.2692526 -0.7918942 -1.0816732 #> #> units: NA
# Dimensions of length one can be drop flq[1, drop=TRUE]
#> [1] 0.03078885
# Replacing part of the object flq['0',,,1]<-0