Summary statistics of data tables.
Mean, median, SD, and count are often data summaries we need to calculate, usually after grouping data based on another column. grafify
has a simple function table_summary
that gives these values for one (or more) quantitative parameters (columns) of a data table after grouping by one (or more columns).
This function uses the base R function aggregate
.
table_summary(data = data_t_pratio, #data table
Ycol = "Cytokine", #quantitative variable
ByGroup = "Genotype") #grouping variable
#> Genotype Cytokine.Mean Cytokine.Median Cytokine.SD Cytokine.Count
#> 1 KO 5.913191 4.513057 6.325244 33
#> 2 WT 2.985028 2.130989 2.690373 33
This example uses two grouping variables.
table_summary(data = data_2w_Festing, #data table
Ycol = "GST", #quantitative variable
ByGroup = c("Strain",
"Treatment")) #grouping variables
#> Strain Treatment GST.Mean GST.Median GST.SD GST.Count
#> 1 129/Ola Control 526.5 526.5 112.42998 2
#> 2 A/J Control 508.5 508.5 142.12846 2
#> 3 BALB/C Control 504.5 504.5 115.25841 2
#> 4 NIH Control 604.0 604.0 226.27417 2
#> 5 129/Ola Treated 742.5 742.5 33.23402 2
#> 6 A/J Treated 929.0 929.0 103.23759 2
#> 7 BALB/C Treated 703.5 703.5 111.01576 2
#> 8 NIH Treated 722.5 722.5 153.44217 2
This example uses mtcars
data.
table_summary(data = mtcars, #data table
Ycol = c("mpg",
"disp"), #quantitative variables
ByGroup = c("gear", #grouping variables
"am"))
#> gear am mpg.Mean mpg.Median mpg.SD mpg.Count disp.Mean
#> 1 3 0 16.10667 15.50 3.371618 15 326.3000
#> 2 4 0 21.05000 21.00 3.069745 4 155.6750
#> 3 4 1 26.27500 25.05 5.414465 8 106.6875
#> 4 5 1 21.38000 19.70 6.658979 5 202.4800
#> disp.Median disp.SD disp.Count
#> 1 318.00 94.85274 15
#> 2 157.15 13.97888 4
#> 3 93.50 37.16298 8
#> 4 145.00 115.49064 5