preparationDT2 {ratios} | R Documentation |
preparationDT2
Description
The function creates a data frame 'new DT2' from the variables vars
of the data set DT2 with corresponding rows to the data set DT1,
hence 'new DT2' and DT1 have the same number of rows.
The aim is to generate corresponding rows for two data sets with differing dimensions and even differing number of rows for each group of rows.
For example if for one row i in DT1 there are 3 corresponding rows (j,k,l) in DT2 the function calculates for the 'new DT2' for each variable of vars
an average over the rows j,k and l of DT2,
generating only one row corresponding to the row i in DT1.
If on the other hand for row y in DT2 there are 4 corresponding rows in DT1 the 'new DT2' will contain four times the row y of DT2 matching the four rows of DT1.
The column group1.vars
(and optional group2.vars
) determines which rows of DT1 and DT2 are corresponding, so group1.vars
in DT1 is the look-up table for creating the 'new DT2'.
Generally DT1 and DT2 have to have the columns in common which are given in group1.vars
, group2.vars
and vars
.
Usage
preparationDT2(DT1, DT2, vars = NULL, group1.vars, group2.vars = NULL,
Errors = FALSE, use_only_DT2 = FALSE, DT2_replace = NULL, minNr = 7,
STD = NULL, return_as_list = FALSE)
Arguments
DT1 |
data.frame or data.table, samples in rows and variables in columns |
DT2 |
data.frame or data.table, samples in rows and variables in columns. |
vars |
optional, character vector of column names of DT1 and DT2, default is function |
group1.vars |
character vector, column name(s) for subsetting DT1 and DT2 |
group2.vars |
optional, column name for subsetting DT1 and DT2 if some entries in |
Errors |
logical, should absolute errors get calculated appended to the list - output? Default is FALSE.
If Errors are set to TRUE it overrides the option |
use_only_DT2 |
logical, default is FALSE. If there are not enough DT2 data of the location should the DT2s of the region be used? If the |
DT2_replace |
mandatory if |
minNr |
minimum numbers of samples/observations for calculating a relative error of observations.
If the number of samples of |
STD |
data set for calculating the relative errors if in DT2 there are less rows per group than |
return_as_list |
logical, should the result get returned as list? Default is FALSE. |
Details
The data set 'new DT2' is generated according to following rules:
If there is more than one row in DT2 with the same entry for group1.vars
for each column in vars
an average (mean) of these rows of DT2 is calculated.
After this operation there is only one row for each entry value of group1.vars
.
Each row of this averaged DT2 is replicated n times, with n being the number of rows of the subset of DT1 with the corresponding value in group1.vars
.
If there are values in column group1.vars
in DT1 which are not in DT2 and if option use_only_DT2
is set to TRUE
empty rows are generated.
If option use_only_DT2
is set to FALSE
, data from 'DT2_replace' are taken as substitute for DT2 to fill these empty rows.
The default 'DT2_replace' are element concentrations from the UpperCrust (Rudnick, R. L., & Gao, S. 2003. Composition of the continental crust. Treatise on geochemistry, 3, 659.)
Value
data.frame, data.table or a list, controlled by option return_as_list
.
If Errors
is set to TRUE return_as_list
is ignored and return value is always a list.
The list contains one element if Errors
is set to FALSE and two elements if Errors
is TRUE:
[[1]] is data.table or data.frame of corresponding DT2s, [[2]] data.table or data.frame of absolute errors of corresponding DT2s.
Author(s)
Solveig Pospiech
See Also
Other ratio functions: Correction.AdheringParticles
,
ratioDT
,
ratio_append_smallest