Extended data frame
exdf.RdAn "extended data frame" (exdf) is an object similar to a data frame,
but which also contains information about the units and categories of each
column.
Usage
exdf(
main_data = data.frame(),
units = NULL,
categories = NULL,
...
)Arguments
- main_data
A data frame.
- units
A data frame with the same columns as
main_data(or a subset of the columns inmain_data) but with just one row, where each entry describes the units for the corresponding column ofmain_data. IfunitsisNULL, it will be initialized withNAfor each column. The units of any columns inmain_datathat are not present inunitswill also be initialized toNA.- categories
A data frame with the same columns as
main_data(or a subset of the columns inmain_data) but with just one row, where each entry describes the category for the corresponding column ofmain_data. IfcategoriesisNULL, it will be initialized withNAfor each column. The categories of any columns inmain_datathat are not present incatgorieswill also be initialized toNA.- ...
Any additional properties to include as entries in the resulting
exdfobject; these must be passed as named arguments.
Details
The exdf class was originally created as a way to represent the
contents of a Licor Excel file in an R structure. In Licor Excel files, each
column has a name, units, and a category; for example, the column for values
of net assimilation rate is called A, has units of micromol / m^2
/ s, and is categorized as a GasEx variable.
From a technical point of view, an exdf object is simply a list with
three required elements: main_data, units, and
categories. Each of these should be a data frame with the same column
names, as described above. It is also possible for an exdf object to
have additional entries such as a filename that stores the name of the
file that was used to create the exdf.
Several S3 methods have been defined for exdf objects, following the
general guidance from
Advanced R on S3 classes:
[<-.exdf
Note that the column names of main_data, units, and
categories must be unique; the make.unique function can
be useful for ensuring this.
Examples
# Example 1: Creating a simple exdf object with two columns (`A` and `B`) and
# default values for its units and categories. There are four values of each
# variable.
exdf(data.frame(A = c(3, 2, 7, 9), B = c(4, 5, 1, 8)))
#>
#> Converting an `exdf` object to a `data.frame` before printing
#>
#> A [NA] (NA) B [NA] (NA)
#> 1 3 4
#> 2 2 5
#> 3 7 1
#> 4 9 8
# Example 2: Creating a simple exdf object with two columns (`A` and `B`) that
# have units of `m` and `s`, respectively, and categories of `Cat1` and `Cat2`,
# respectively. There are four values of each variable.
exdf(
data.frame(A = c(3, 2, 7, 9), B = c(4, 5, 1, 8)),
data.frame(A = 'm', B = 's'),
data.frame(A = 'Cat1', B = 'Cat2')
)
#>
#> Converting an `exdf` object to a `data.frame` before printing
#>
#> A [Cat1] (m) B [Cat2] (s)
#> 1 3 4
#> 2 2 5
#> 3 7 1
#> 4 9 8