Trim FLR objects using named dimensions

trim(x, ...)

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

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

# S4 method for FLS
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)

See also

FLQuant, FLStock, FLCohort, FLIndex

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 -2.725535 -0.455349 -0.210886 -0.346662 0.714217 0.767133 #> 2 -0.305181 0.392446 -1.263650 -0.838827 -1.162195 -0.608500 #> 3 -0.634887 1.516195 -0.012322 -1.409560 0.849920 -0.874672 #> 4 -1.443674 0.573833 -0.003874 0.037726 -0.123669 0.107419 #> 5 0.486917 -0.174562 -0.167932 2.408326 -0.999429 0.110223 #> 6 -0.607496 -1.083028 0.091816 -1.122340 0.013876 -0.127320 #> 7 -1.045196 -0.074940 -1.107337 0.178444 -0.308229 0.077139 #> 8 1.107602 -1.981823 -0.846779 -0.068795 0.968329 -1.683823 #> 9 -0.368490 -1.734741 -1.367585 -0.596146 2.532179 1.648248 #> 10 -1.002448 0.087698 -0.284313 -1.097759 -0.244155 -0.456134 #> #> 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 -2.725535 -0.455349 -0.210886 -0.346662 0.714217 0.767133 #> 2 -0.305181 0.392446 -1.263650 -0.838827 -1.162195 -0.608500 #> 3 -0.634887 1.516195 -0.012322 -1.409560 0.849920 -0.874672 #> 4 -1.443674 0.573833 -0.003874 0.037726 -0.123669 0.107419 #> 5 0.486917 -0.174562 -0.167932 2.408326 -0.999429 0.110223 #> 6 -0.607496 -1.083028 0.091816 -1.122340 0.013876 -0.127320 #> 7 -1.045196 -0.074940 -1.107337 0.178444 -0.308229 0.077139 #> 8 1.107602 -1.981823 -0.846779 -0.068795 0.968329 -1.683823 #> 9 -0.368490 -1.734741 -1.367585 -0.596146 2.532179 1.648248 #> 10 -1.002448 0.087698 -0.284313 -1.097759 -0.244155 -0.456134 #> #> 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 -2.72554 -0.45535 -0.21089 -0.34666 0.71422 0.76713 #> 2 -0.30518 0.39245 -1.26365 -0.83883 -1.16219 -0.60850 #> #> units: NA
# Now on an FLStock data(ple4) summary(trim(ple4, year=1990:1995))
#> An object of class "FLStock" #> #> Name: Plaice in IV #> Description: Imported from a VPA file. ( N:\Projecten\ICES WG\Demersale werkgroep WGNSS [...] #> 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 #> #> catch : [ 1 6 1 1 1 1 ], units = t #> catch.n : [ 10 6 1 1 1 1 ], units = 10^3 #> catch.wt : [ 10 6 1 1 1 1 ], units = kg #> discards : [ 1 6 1 1 1 1 ], units = t #> discards.n : [ 10 6 1 1 1 1 ], units = 10^3 #> discards.wt : [ 10 6 1 1 1 1 ], units = kg #> landings : [ 1 6 1 1 1 1 ], units = t #> landings.n : [ 10 6 1 1 1 1 ], units = 10^3 #> landings.wt : [ 10 6 1 1 1 1 ], units = kg #> stock : [ 1 6 1 1 1 1 ], units = t #> stock.n : [ 10 6 1 1 1 1 ], units = 10^3 #> stock.wt : [ 10 6 1 1 1 1 ], units = kg #> m : [ 10 6 1 1 1 1 ], units = m #> mat : [ 10 6 1 1 1 1 ], units = #> harvest : [ 10 6 1 1 1 1 ], units = f #> harvest.spwn : [ 10 6 1 1 1 1 ], units = #> m.spwn : [ 10 6 1 1 1 1 ], units =
# 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: Plaice in IV #> Description: Imported from a VPA file. ( N:\Projecten\ICES WG\Demersale werkgroep WGNSS [...] #> Quant: age #> Dims: age year unit season area iter #> 4 52 1 1 1 1 #> #> Range: min max pgroup minyear maxyear minfbar maxfbar #> 1 4 NA 1957 2008 2 4 #> #> catch : [ 1 52 1 1 1 1 ], units = t #> catch.n : [ 4 52 1 1 1 1 ], units = 10^3 #> catch.wt : [ 4 52 1 1 1 1 ], units = kg #> discards : [ 1 52 1 1 1 1 ], units = t #> discards.n : [ 4 52 1 1 1 1 ], units = 10^3 #> discards.wt : [ 4 52 1 1 1 1 ], units = kg #> landings : [ 1 52 1 1 1 1 ], units = t #> landings.n : [ 4 52 1 1 1 1 ], units = 10^3 #> landings.wt : [ 4 52 1 1 1 1 ], units = kg #> stock : [ 1 52 1 1 1 1 ], units = t #> stock.n : [ 4 52 1 1 1 1 ], units = 10^3 #> stock.wt : [ 4 52 1 1 1 1 ], units = kg #> m : [ 4 52 1 1 1 1 ], units = m #> mat : [ 4 52 1 1 1 1 ], units = #> harvest : [ 4 52 1 1 1 1 ], units = f #> harvest.spwn : [ 4 52 1 1 1 1 ], units = #> m.spwn : [ 4 52 1 1 1 1 ], units =