Skip to contents

Extract or replace parts of an FLR Object

Usage

# 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 FLPar
$(x, name) <- value

# 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, k, l, m, n, ..., drop = FALSE)

# 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, 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 on any of the six dimensions.

...

indices specifying elements to extract or replace by dimension name.

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 the same class, or simpler if drop=TRUE, 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

Author

The FLR Team

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      1997     
#>   0  0.424188  1.672883 -0.387214 -0.690538 -0.208883  2.126850  2.039369
#>    year
#> age 1998      1999      2000     
#>   0  0.022295 -1.146200  0.454342
#> 
#> , , unit = unique, season = 2, area = unique
#> 
#>    year
#> age 1991      1992      1993      1994      1995      1996      1997     
#>   0 -0.162676  1.321781  0.429147  0.677684 -1.900061 -0.788259 -0.102909
#>    year
#> age 1998      1999      2000     
#>   0  1.035931 -1.041668  1.993110
#> 
#> , , unit = unique, season = 3, area = unique
#> 
#>    year
#> age 1991      1992      1993      1994      1995      1996      1997     
#>   0  1.123839  0.132992 -0.429380  0.065487 -1.153398  0.075106 -0.338936
#>    year
#> age 1998      1999      2000     
#>   0  1.233390  0.237425 -0.639535
#> 
#> , , unit = unique, season = 4, area = unique
#> 
#>    year
#> age 1991      1992      1993      1994      1995      1996      1997     
#>   0 -0.902815  1.382911 -0.830214 -0.828604  0.149679 -2.102152  0.060899
#>    year
#> age 1998      1999      2000     
#>   0  1.877744  1.012002  1.129835
#> 
#> 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.4241876  1.6728826 -0.3872136 -0.6905379 -0.2088827
#>   1  1.0631020 -0.3543612 -0.7854327 -0.5585420 -1.3994105
#>   2  1.0487126  0.9463479 -1.0567369 -0.5366633  0.2585373
#>   3 -0.0381029  1.3168264 -0.7955414  0.2271271 -0.4417995
#>   4  0.4861489 -0.2966400 -1.7562754  0.9784549  0.5685999
#> 
#> , , unit = unique, season = 2, area = unique
#> 
#>    year
#> age 1991       1992       1993       1994       1995      
#>   0 -0.1626763  1.3217810  0.4291474  0.6776836 -1.9000608
#>   1 -0.8273102 -1.1197108  0.1221034  0.0384995  0.9357843
#>   2  1.8765056  0.5145998 -1.1380124 -0.3563812 -0.3090515
#>   3  0.7664402 -1.5090998 -0.5580151  0.7828441  0.2630667
#>   4  0.9799567  1.5327415  1.0525385  0.8044116 -1.7905919
#> 
#> , , unit = unique, season = 3, area = unique
#> 
#>    year
#> age 1991       1992       1993       1994       1995      
#>   0  1.1238388  0.1329921 -0.4293801  0.0654866 -1.1533984
#>   1 -0.3970015  0.3764993  1.3604613 -1.0985089 -0.3406379
#>   2 -0.8232612  1.1387077 -0.0708574 -0.6331782  0.7863626
#>   3 -0.5788846  1.2412631 -0.2721537 -2.0636545 -1.2705131
#>   4  1.7637894  0.6120909 -2.4466800  2.6489320  0.5421415
#> 
#> , , unit = unique, season = 4, area = unique
#> 
#>    year
#> age 1991       1992       1993       1994       1995      
#>   0 -0.9028149  1.3829109 -0.8302143 -0.8286035  0.1496794
#>   1  1.3176337  0.0031259 -0.5035929  0.2897745 -1.4333211
#>   2  1.1001897 -0.0778868 -1.1936412 -0.4800535 -0.0103033
#>   3  1.2037678  0.4414282 -0.7517233 -0.6048294 -0.2122360
#>   4 -1.4312708  0.1289229  1.4558414  1.4601102 -0.9063402
#> 
#> 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      1997     
#>   0  0.424188  1.672883 -0.387214 -0.690538 -0.208883  2.126850  2.039369
#>   1  1.063102 -0.354361 -0.785433 -0.558542 -1.399410  0.424858  0.449454
#>    year
#> age 1998      1999      2000     
#>   0  0.022295 -1.146200  0.454342
#>   1  0.603611  0.846185 -0.855203
#> 
#> , , unit = unique, season = 3, area = unique
#> 
#>    year
#> age 1991      1992      1993      1994      1995      1996      1997     
#>   0  1.123839  0.132992 -0.429380  0.065487 -1.153398  0.075106 -0.338936
#>   1 -0.397001  0.376499  1.360461 -1.098509 -0.340638  0.558514 -0.075574
#>    year
#> age 1998      1999      2000     
#>   0  1.233390  0.237425 -0.639535
#>   1  0.340424 -1.312814 -0.845196
#> 
#> 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      1997     
#>   0  0.424188  1.672883 -0.387214 -0.690538 -0.208883  2.126850  2.039369
#>    year
#> age 1998      1999      2000     
#>   0  0.022295 -1.146200  0.454342
#> 
#> , , unit = unique, season = 2, area = unique
#> 
#>    year
#> age 1991      1992      1993      1994      1995      1996      1997     
#>   0 -0.162676  1.321781  0.429147  0.677684 -1.900061 -0.788259 -0.102909
#>    year
#> age 1998      1999      2000     
#>   0  1.035931 -1.041668  1.993110
#> 
#> , , unit = unique, season = 3, area = unique
#> 
#>    year
#> age 1991      1992      1993      1994      1995      1996      1997     
#>   0  1.123839  0.132992 -0.429380  0.065487 -1.153398  0.075106 -0.338936
#>    year
#> age 1998      1999      2000     
#>   0  1.233390  0.237425 -0.639535
#> 
#> , , unit = unique, season = 4, area = unique
#> 
#>    year
#> age 1991      1992      1993      1994      1995      1996      1997     
#>   0 -0.902815  1.382911 -0.830214 -0.828604  0.149679 -2.102152  0.060899
#>    year
#> age 1998      1999      2000     
#>   0  1.877744  1.012002  1.129835
#> 
#> units:  NA 
  flq[,'1991']
#> An object of class "FLQuant"
#> , , unit = unique, season = 1, area = unique
#> 
#>    year
#> age 1991     
#>   0  0.424188
#>   1  1.063102
#>   2  1.048713
#>   3 -0.038103
#>   4  0.486149
#> 
#> , , unit = unique, season = 2, area = unique
#> 
#>    year
#> age 1991     
#>   0 -0.162676
#>   1 -0.827310
#>   2  1.876506
#>   3  0.766440
#>   4  0.979957
#> 
#> , , unit = unique, season = 3, area = unique
#> 
#>    year
#> age 1991     
#>   0  1.123839
#>   1 -0.397001
#>   2 -0.823261
#>   3 -0.578885
#>   4  1.763789
#> 
#> , , unit = unique, season = 4, area = unique
#> 
#>    year
#> age 1991     
#>   0 -0.902815
#>   1  1.317634
#>   2  1.100190
#>   3  1.203768
#>   4 -1.431271
#> 
#> 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.424188  1.672883 -0.387214 -0.690538 -0.208883
#>   1  1.063102 -0.354361 -0.785433 -0.558542 -1.399410
#>   2  1.048713  0.946348 -1.056737 -0.536663  0.258537
#>   3 -0.038103  1.316826 -0.795541  0.227127 -0.441799
#>   4  0.486149 -0.296640 -1.756275  0.978455  0.568600
#> 
#> units:  NA 

# Dimensions of length one can be drop
  flq[1, drop=TRUE]
#> [1] 0.4241876

# Replacing part of the object
  flq['0',,,1]<-0