Use R's sweep method on FLCore classes
# S4 method for FLArray sweep(x, MARGIN, STATS, FUN = "-", check.margin = TRUE, ...) # S4 method for FLPar sweep(x, MARGIN, STATS, FUN = "-", check.margin = TRUE, ...)
These methods call base R sweep
method on **FLCore** classes and then ensure
that the returned object is of same class.
sweep(x, MARGIN, STATS, FUN = "-", check.margin = TRUE, ...)
flq <- FLQuant(rlnorm(90), dim=c(3,10), units='kg') # Get ratio of max value by year sweep(flq, 2, apply(flq, 2, max), "/")#> An object of class "FLQuant" #> , , unit = unique, season = all, area = unique #> #> year #> quant 1 2 3 4 5 6 7 8 #> 1 1.000000 0.100070 0.698939 0.455343 0.144608 0.699713 0.098621 0.682368 #> 2 0.974665 1.000000 0.573980 0.799384 0.184175 0.390755 1.000000 1.000000 #> 3 0.836174 0.122749 1.000000 1.000000 1.000000 1.000000 0.089668 0.601876 #> year #> quant 9 10 #> 1 0.280207 1.000000 #> 2 0.207013 0.246812 #> 3 1.000000 0.155917 #> #> units: kg