Skip to contents

Delete the dimensions of an array which have only one level.

Usage

# S4 method for FLArray
drop(x)

Details

This method calls R's base::drop on the @.Data slot of an FLArray. Dimensions of length one are thus dropped, as is the class attribute and the units slot, and an array of equal or less dimensions, a matrix or a vector is returned.

On an FLQuant object with

See also

Author

The FLR Team

Examples

x <- FLQuant(1:3, dim=c(3,3))
drop(x)
#>      year
#> quant 1 2 3
#>     1 1 1 1
#>     2 2 2 2
#>     3 3 3 3
is(drop(x))
#> [1] "matrix"      "array"       "replValueSp" "structure"   "vector"     
dim(drop(x))
#> [1] 3 3

# Result of drop can be used for matrix algebra
# for example to calculate aging error

data(ple4)
aging.error <- diag(0.8, 10)
diag(aging.error[-1,]) <- c(rep(0.1, 8), 0.2)
diag(aging.error[, -1]) <- c(0.2, rep(0.1, 8))
t(aging.error) %*% drop(catch.n(ple4))
#>        year
#>              1957      1958       1959       1960       1961       1962
#>    [1,] 38176.254 65315.932  92053.464  93170.535  97674.521  67370.315
#>    [2,] 48588.858 76785.722 124538.396 153447.291 142787.777 143902.922
#>    [3,] 73152.549 55491.642  80331.220 113728.840 130557.498 127596.723
#>    [4,] 56372.168 62683.002  42607.667  55246.135  74768.782  88867.601
#>    [5,] 32265.414 37598.882  40837.899  27083.451  34665.389  48021.628
#>    [6,] 13184.204 21904.368  24816.102  25647.327  16603.400  21983.837
#>    [7,] 11698.056  9898.540  14438.855  14856.067  14884.680  10028.957
#>    [8,]  9431.123  8450.624   6925.418   9628.640   9452.699   9280.768
#>    [9,]  7711.595  9456.291   9491.492   7746.383   8631.265   8313.749
#>   [10,]  9972.795 12523.807  14073.860  12861.949  10657.310  11452.109
#>        year
#>               1963       1964       1965       1966       1967       1968
#>    [1,]  52711.042 145872.503  78090.881  42847.291  40203.649  50319.560
#>    [2,] 115813.299 139658.823 378283.895 143133.323  98309.829  86963.769
#>    [3,] 148725.765 121759.060 149618.116 387395.970 132373.139  99423.466
#>    [4,]  89080.067  90490.158  66822.472  98898.381 223597.642  83548.410
#>    [5,]  57833.831  55179.508  52394.498  37361.280  56480.936 135294.490
#>    [6,]  31802.423  37737.836  33194.963  29628.113  21270.257  34415.433
#>    [7,]  13478.484  18246.110  19252.144  16339.143  15392.196  12156.348
#>    [8,]   6199.196   7897.852   9860.546  10209.505   9186.716   9272.261
#>    [9,]   9235.500   7732.508   8084.490   8364.535   8547.831   8362.603
#>   [10,]  13993.587  16173.170  13690.447  11330.475  10867.459  11896.684
#>        year
#>              1969       1970      1971      1972       1973       1974
#>    [1,] 96333.995 107770.028  71255.09  57232.70 204487.172 203861.276
#>    [2,] 99498.274 137423.175 126279.39  90031.92 118483.670 296810.619
#>    [3,] 74451.470  70623.471  97340.07 101838.25  77038.371  89095.880
#>    [4,] 59803.960  43785.217  44696.08  67630.84  71425.482  49041.247
#>    [5,] 52925.909  38809.684  28744.23  29762.19  43018.799  39512.485
#>    [6,] 88511.812  33835.508  24966.90  18433.35  18152.424  22809.347
#>    [7,] 20990.194  49601.654  19703.48  15180.60  11022.392   9752.265
#>    [8,]  7264.125  11941.598  29393.77  12448.13   9556.047   6593.822
#>    [9,]  8729.100   7633.819  10511.81  22657.76  12150.635  10228.508
#>   [10,] 13040.648  14117.535  13667.33  14732.69  22020.998  18359.021
#>        year
#>               1975       1976       1977       1978       1979       1980
#>    [1,] 173842.112 166383.938 263021.542 230486.462 209764.902 204323.810
#>    [2,] 250542.355 188093.102 187227.288 240027.198 221405.948 234661.550
#>    [3,] 213496.208 159879.310 114581.130 106336.920 147614.640 141710.424
#>    [4,]  54996.315 120711.305  95973.257  71226.601  64474.371  81115.737
#>    [5,]  23970.252  28271.317  67269.761  57679.491  41162.293  33081.992
#>    [6,]  18533.072  11658.958  15662.848  39755.196  31675.903  20320.805
#>    [7,]  11290.702   9699.382   6662.906   8989.515  20394.959  15408.802
#>    [8,]   5519.107   6524.155   5699.114   3760.989   4706.924  10597.272
#>    [9,]   7330.525   5773.734   5621.181   4695.250   3445.455   3792.677
#>   [10,]  14677.998  10908.634   8176.022   6988.951   6297.555   5527.177
#>        year
#>               1981       1982       1983       1984       1985       1986
#>    [1,] 175356.448 328043.196 296183.200 295761.390 403988.238 908293.968
#>    [2,] 268681.429 294940.273 450506.410 351122.148 352261.794 571700.592
#>    [3,] 160666.685 188037.720 197722.141 305277.630 229776.217 225335.480
#>    [4,]  71558.181  77939.227  93632.016 111951.649 176563.171 133691.140
#>    [5,]  36598.636  30400.925  34071.422  44010.467  57565.044  92222.111
#>    [6,]  15412.687  16852.781  14038.572  16245.382  21956.231  29098.307
#>    [7,]  10156.049   7856.087   8758.517   7471.334   8631.471  11025.602
#>    [8,]   8069.958   5367.888   4347.817   5188.325   4404.222   4684.949
#>    [9,]   6870.012   5765.584   4577.667   3916.764   4189.576   3635.567
#>   [10,]   5319.717   7002.957   6903.870   5835.050   5011.270   5283.513
#>        year
#>               1987       1988       1989       1990       1991       1992
#>    [1,] 458871.907 347230.074 240019.886 194163.118 176240.926 158676.374
#>    [2,] 956560.787 532682.341 433150.294 310694.782 266904.834 247735.376
#>    [3,] 357950.947 660050.080 342818.580 291258.630 219775.510 197182.610
#>    [4,] 128591.470 198746.408 310652.866 169742.274 153165.900 121080.411
#>    [5,]  68877.220  63053.330  93402.313 153624.222  87752.801  81598.860
#>    [6,]  44966.467  32532.423  29474.627  44286.032  71900.815  42124.368
#>    [7,]  13547.395  19496.605  13398.106  11683.172  18205.211  30022.162
#>    [8,]   5493.325   6183.720   8238.922   5549.991   5250.302   8732.009
#>    [9,]   3859.525   4087.030   3798.566   4685.689   3939.345   4246.328
#>   [10,]   5578.730   5353.507   4336.547   3603.275   4416.685   4990.956
#>        year
#>               1993       1994       1995       1996       1997       1998
#>    [1,] 104858.040  87468.382 114345.334 107393.640 243349.540 143521.481
#>    [2,] 208427.850 136951.178 138892.876 219879.240 283410.620 602063.015
#>    [3,] 177719.550 146557.370 105860.074 132122.707 225386.010 256118.540
#>    [4,] 105104.499  91943.704  78881.133  61666.989  73903.448  93225.774
#>    [5,]  62928.618  53223.225  46289.210  38859.304  28018.039  29190.606
#>    [6,]  40302.421  31041.116  25777.158  22173.277  18285.823  12302.744
#>    [7,]  18838.081  17432.184  13236.074  11415.248   9890.450   7285.893
#>    [8,]  14411.523   7630.588   6782.762   5709.879   5139.673   3948.188
#>    [9,]   5508.614   6575.734   3690.761   3737.965   3489.209   2977.472
#>   [10,]   4767.025   4126.668   4246.825   3635.068   3792.407   3476.110
#>        year
#>               1999       2000       2001       2002        2003       2004
#>    [1,]  91766.427 116668.582  96769.770 235946.978 126618.9844 203103.850
#>    [2,] 218364.404 151211.968 183925.600 212364.852 457429.1786 195761.307
#>    [3,] 430556.960 155854.240 141926.870 184540.550 169590.2500 267988.582
#>    [4,] 115078.475 211770.333  99323.690  86438.954  76772.3450  68925.460
#>    [5,]  36311.072  51742.438  98443.716  45781.327  36676.5934  32152.002
#>    [6,]  11677.704  13701.143  21266.383  42425.209  21379.6032  17002.041
#>    [7,]   4209.319   3869.870   5128.602   9133.079  17663.5171   7952.854
#>    [8,]   2556.271   1575.633   1705.657   2314.220   3457.6842   5189.243
#>    [9,]   2191.395   1590.274   1098.546    991.607    986.0152   1251.162
#>   [10,]   2721.661   2037.141   1591.542   1261.783   1127.1414   1118.878
#>        year
#>               2005       2006       2007       2008       2009       2010
#>    [1,] 165068.770 136261.796 170546.878 150387.616 151489.712 180657.964
#>    [2,] 259744.460 188181.751 192936.142 250794.351 192075.428 167320.836
#>    [3,] 106393.090 167971.973 127624.970 127211.887 155874.250 124687.320
#>    [4,] 104614.944  53956.593  77999.550  57292.482  64112.090  97084.183
#>    [5,]  28703.676  46780.688  24181.193  35589.168  28019.881  35265.850
#>    [6,]  14235.643  12888.246  23251.536  12448.096  18914.460  15107.858
#>    [7,]   6347.179   6053.966   6409.973  12599.167   6732.667  10854.519
#>    [8,]   2614.521   2543.394   2614.628   2960.500   5326.064   3181.155
#>    [9,]   1988.586   1242.851   1147.310   1096.831   1401.935   2351.224
#>   [10,]   1136.210   1478.129   1249.105   1258.377   1486.094   1838.269
#>        year
#>               2011       2012       2013       2014       2015       2016
#>    [1,] 148365.212  99088.963 121281.373 187987.757 124900.543 114445.677
#>    [2,] 185752.575 202610.230 189256.503 226392.973 224693.259 135925.886
#>    [3,] 127143.170 176925.568 203316.470 168708.655 177490.162 180588.718
#>    [4,]  91996.510  95665.146 123076.970 135834.170 117144.030 126595.550
#>    [5,]  57658.781  57218.806  58469.035  72360.875  78170.831  69278.102
#>    [6,]  20082.379  33516.726  31333.439  30692.623  38331.743  43593.693
#>    [7,]   8383.028  10434.207  15996.115  15670.625  16543.569  20874.094
#>    [8,]   5059.804   4024.694   5225.981   8585.640   8146.300   7783.139
#>    [9,]   2048.624   3394.421   3321.345   4092.181   5357.450   4858.489
#>   [10,]   3037.990   3555.298   4978.874   5691.126   6302.187   7265.799
#>        year
#>               2017
#>    [1,] 106412.493
#>    [2,] 149020.179
#>    [3,] 116194.564
#>    [4,] 124063.590
#>    [5,]  77473.116
#>    [6,]  40462.532
#>    [7,]  21791.847
#>    [8,]   8700.510
#>    [9,]   4617.680
#>   [10,]   7362.845