df_to_array: Convert Data frame of Array Entries to Array of entries

View source: R/guam_BB.R

df_to_arrayR Documentation

Convert Data frame of Array Entries to Array of entries

Description

Convert a Data Frame of array entries (as returned by dplyr::summarise) to an Array containing the entries

Usage

df_to_array(x, l)

Arguments

x

data frame where each row represents the index of a value, along with the value itself (as returned by the summarise method in library dplyr)

l

list of reference vectors whose lengths give the dimensions of the output array (first vector length first dimension of the output, etc.)

Value

Array whose dimensions match the dimensions of l and whose entries represent data for the corresponding indices from x. Non-specified entries are assumed to be zero. For example, if inputs are:

        x = 1 1 7     l = list(c(1,2), c(1,7,9))
            1 2 5             ^        ^
            2 2 1             |        |
            2 3 2             |        second dimension is of length length(c(1,7,9)) = 3
            ^ ^ ^             first dimension is of length length(c(1,2)) = 2
            | | |
            | | values for each index
            | second dimension indices
            first dimension indices

        Then the output will be:

        res = [7 5 0  <-- 2 x 3 array with values as specified by the last column of x, and other entries zero
               0 1 2]

PIFSCstockassessments/expalg.cie documentation built on June 15, 2022, 1:41 a.m.