Flexibly generate output tables based on a data frame and derived statistical quantities

The function allows to define a table composed of user-define output columns being specified by strings and keywords.

IQRtable(data, stat, ...)

Arguments

data

data frame, the input.

stat

a statistical function as returned by statSE or statCI.

...

defining the outputs, e.g. "Value + 95%CI" = "value [lower.95, upper.95]". See also details and examples.

Value

Character matrix with one column for each argument in .... The first element in a column is always the name of the argument name in ... (header), the other elements correspond to the formatted values. For exporting use as.data.frame.IQRtable before IQRoutputTable

Details

Keywords in the strings in ... are replaced by values provided by stat or found in data. First, all statistical key words are replaced (see statSE and statCI for a list of keywords). Second, the employed column names of data are replace by the data values. All non-recognized symbols/words are returned as they are.

Keywords can be composed to flexibly control the output format. For example value (rse%) could return 1.36 (18.5%) for a value of 1.3564 and a standard error of 0.25123.

See also

Examples

mydata <- data.frame( parameter = c("A", "B"), value = c(pi, pi), lower = c(1.5214, -Inf), upper = c(37.4831, 4.27134), se = c(0.082723, 0.57) ) as_IQRtable(mydata)
#> parameter | value | lower | upper | se #> ---------------------------------------------------------- #> A | 3.14159265358979 | 1.5214 | 37.4831 | 0.082723 #> B | 3.14159265358979 | -Inf | 4.27134 | 0.57
mytable <- IQRtable( data = mydata, stat = statSE(value, se), # Output `Parameter` = "parameter", `Value` = "value", `CI [95%]` = "[lower.95, upper.95]", `RSE [%]` = "rse%", `Value + 68% CI` = "value + [lower.68, upper.68]", `Value (RSE)` = "value (rse%)" ) print(mytable)
#> Parameter | Value | CI [95%] | RSE [%] | Value + 68% CI | Value [RSE] #> -------------------------------------------------------------------------------------- #> A | 3.142 | [2.979, 3.304] | 2.633% | 3.142 + [3.059, 3.224] | 3.142 (2.633%) #> B | 3.14 | [2.02, 4.26] | 18.1% | 3.14 + [2.57, 3.71] | 3.14 (18.1%)
# To export the table, convert to data frame and use IQRoutputTable() # IQRoutputTable(as.data.frame(mytable), filename = "mytable.txt") mytable <- IQRtable( data = mydata, stat = statCI(value, lower, upper, CL = 0.68), # Output `Parameter` = "parameter", `Value` = "value", `CI [95%]` = "[lower.95, upper.95]", `RSE [%]` = "rse%", `Value + 68% CI` = "value + [lower.68, upper.68]", `Value (RSE)` = "value (rse%)" ) print(mytable)
#> Parameter | Value | CI [95%] | RSE [%] | Value + 68% CI | Value [RSE] #> ------------------------------------------------------------------------ #> A | 3.1 | [-0.1, 71] | 600% | 3.1 + [1.5, 37] | 3.1 (600%) #> B | 3.1 | [--, 5.4] | --% | 3.1 + [--, 4.3] | 3.1 (--%)