Skip to contents

Trim FLR objects using named dimensions

Usage

trim(x, ...)

# S4 method for FLArray
trim(x, ...)

# S4 method for FLComp
trim(x, ...)

# S4 method for FLS
trim(x, ...)

# S4 method for FLBiol
trim(x, ...)

Details

Subsetting of FLR objects can be carried out with dimension names by using trim. A number of dimension names and selected dimensions are passed to the method and those are used to subset the input object.

Exceptions are made for those classes where certain slots might differ in one or more dimensions. If trim is applied to an FLQuant object of length 1 in its first dimension and with dimension name equal to 'all', values to trim specified for that dimension will be ignored. For example, FLStock objects contain slots with length=1 in their first dimension. Specifying values to trim over the first dimension will have no effect on those slots (catch, landings, discards, and stock). Calculations might need to be carried out to recalculate those slots (e.g. using computeCatch, computeLandings, computeDiscards and computeStock) if their quant-structured counterparts are modified along the first dimension.

Generic function

trim(x)

Author

The FLR Team

Examples


flq <- FLQuant(rnorm(90), dimnames=list(age=1:10, year=2000:2016))

trim(flq, year=2000:2005)
#> An object of class "FLQuant"
#> , , unit = unique, season = all, area = unique
#> 
#>     year
#> age  2000      2001      2002      2003      2004      2005     
#>   1  -0.280422 -0.430205  0.120662 -0.848278  1.440049  1.352135
#>   2   0.052818  0.344476  0.121017  0.735323 -0.484485 -1.057141
#>   3  -1.922824 -0.471077  1.227001  0.371304  0.328686 -0.062179
#>   4  -0.488962 -0.550618 -1.540746 -1.541355 -0.266258 -0.359563
#>   5   0.650278  0.554343 -0.128456  0.064827  0.503252 -0.843722
#>   6  -0.178181  0.725959  0.378941 -2.254289 -0.465968  0.359364
#>   7   1.802803 -1.568867  0.306811  1.782011  0.492407 -0.342467
#>   8   1.042206 -0.014456  0.185899  0.815925  0.789373 -0.141715
#>   9   0.591269 -0.591412  0.851600 -0.313564 -0.123026  2.520258
#>   10  0.512747 -1.203682  0.165703  1.138641  0.337176  1.847825
#> 
#> units:  NA 
# which is equivalent to
window(flq, start=2000, end=2005)
#> An object of class "FLQuant"
#> , , unit = unique, season = all, area = unique
#> 
#>     year
#> age  2000      2001      2002      2003      2004      2005     
#>   1  -0.280422 -0.430205  0.120662 -0.848278  1.440049  1.352135
#>   2   0.052818  0.344476  0.121017  0.735323 -0.484485 -1.057141
#>   3  -1.922824 -0.471077  1.227001  0.371304  0.328686 -0.062179
#>   4  -0.488962 -0.550618 -1.540746 -1.541355 -0.266258 -0.359563
#>   5   0.650278  0.554343 -0.128456  0.064827  0.503252 -0.843722
#>   6  -0.178181  0.725959  0.378941 -2.254289 -0.465968  0.359364
#>   7   1.802803 -1.568867  0.306811  1.782011  0.492407 -0.342467
#>   8   1.042206 -0.014456  0.185899  0.815925  0.789373 -0.141715
#>   9   0.591269 -0.591412  0.851600 -0.313564 -0.123026  2.520258
#>   10  0.512747 -1.203682  0.165703  1.138641  0.337176  1.847825
#> 
#> units:  NA 

trim(flq, year=2000:2005, age=1:2)
#> An object of class "FLQuant"
#> , , unit = unique, season = all, area = unique
#> 
#>    year
#> age 2000      2001      2002      2003      2004      2005     
#>   1 -0.280422 -0.430205  0.120662 -0.848278  1.440049  1.352135
#>   2  0.052818  0.344476  0.121017  0.735323 -0.484485 -1.057141
#> 
#> units:  NA 


# Now on an FLStock
data(ple4)
summary(trim(ple4, year=1990:1995))
#> An object of class "FLStock"
#> 
#> Name: PLE 
#> Description: Plaice in IV. ICES WGNSSK 2018. FLAAP 
#> Quant: age 
#> Dims:  age 	year	unit	season	area	iter
#> 	10	6	1	1	1	1	
#> 
#> Range:  min	max	pgroup	minyear	maxyear	minfbar	maxfbar 
#> 	1	10	10	1990	1995	2	6	
#> 
#> Metrics: 
#>   rec: 550376 - 1083810  (1000) 
#>   ssb: 222203 - 396458  (t) 
#>   catch: 132629 - 250604  (t) 
#>   fbar: 0.60 - 0.61  (f) 

# If 'age' is trimmed in ple4, catch, landings and discards need to be
# recalculated
  shpl4 <- trim(ple4, age=1:4)
  landings(shpl4) <- computeLandings(shpl4)
  discards(shpl4) <- computeDiscards(shpl4)
  catch(shpl4) <- computeCatch(shpl4)
  summary(shpl4)
#> An object of class "FLStock"
#> 
#> Name: PLE 
#> Description: Plaice in IV. ICES WGNSSK 2018. FLAAP 
#> Quant: age 
#> Dims:  age 	year	unit	season	area	iter
#> 	4	61	1	1	1	1	
#> 
#> Range:  min	max	pgroup	minyear	maxyear	minfbar	maxfbar 
#> 	1	4	NA	1957	2017	2	4	
#> 
#> Metrics: 
#>   rec: 367450 - 4303680  (1000) 
#>   ssb: 91016 - 316967  (t) 
#>   catch: 36219 - 253152  (t) 
#>   fbar: 0.22 - 0.71  (f)