Description Usage Arguments Details Value Examples
Paste together information, often statistics, from two groups. There are two predefined combinations: mean(sd) and median[min,max], but user may also paste any single measure together.
1 2 3 4 |
data |
input dataset. User must use consistent naming throughout, with an underscore to separate the group names from the measures (i.e. |
vars_to_paste |
vector of names of common measures to paste together. Can be the predefined 'median_min_max' or 'mean_sd', or any variable as long as they have matching columns for each group (i.e. Group1_MyMeasure and Group2_MyMeasure). Multiple measures can be requested. Default: "all" will run 'median_min_max' and 'mean_sd', as well as any pairs of columns in the proper format. |
first_name |
name of first group (string before '_') . Default is 'Group1'. |
second_name |
name of second group (string before '_'). Default is 'Group2'. |
sep_val |
value to be pasted between the two measures. Default is ' vs. '. |
na_str_out |
the character to replace missing values with. |
alternative |
a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". Will be used to determine the character to be pasted between the group names ( |
digits |
integer indicating the number of decimal places to round to before pasting for numeric variables. Default is 0. |
trailing_zeros |
logical indicating if trailing zeros should be included (i.e. 0.100 instead of 0.1). Note if set to TRUE output is a character vector. |
keep_all |
logical indicating if all remaining, unpasted variables in |
verbose |
a logical variable indicating if warnings and messages should be displayed. Default FALSE. |
User must use consistant naming throughout, with a underscore to separate the group names from the measures (i.e. Group1_mean
and Group2_mean
). There also must be columns defining the group names (i.e. Group1
and Group2
), which are used to form the Comparison
variable.
alternative
included as a parameter so the direction can easily be seen in one-sided test. If "two.sided" is selected the value to be pasted between the two group names will be set to sep_val
, where "greater" will use " > " and "less" with use " < " as the pasting value.
data.frame with all the pasted values requested. Each name will have '_comparison' at the end of the names (i.e. mean_comparison, median_comparison, ...)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | # Same examples on data.table
library(data.table)
data(exampleData_BAMA)
descriptive_stats_by_group <- exampleData_BAMA[, .(
Group1 = unique(group[group == 1]), Group2 = unique(group[group == 2]),
Group1_n = length(magnitude[group == 1]), Group2_n = length(magnitude[group == 2]),
Group1_mean = mean(magnitude[group == 1]), Group2_mean = mean(magnitude[group == 2]),
Group1_sd = sd(magnitude[group == 1]), Group2_sd = sd(magnitude[group == 2]),
Group1_median = median(magnitude[group == 1]), Group2_median = median(magnitude[group == 2]),
Group1_min = min(magnitude[group == 1]), Group2_min = min(magnitude[group == 2]),
Group1_max = max(magnitude[group == 1]), Group2_max = max(magnitude[group == 2])
), by = .(visitno,antigen)]
paste_tbl_grp(data = descriptive_stats_by_group, vars_to_paste = 'all',
first_name = 'Group1', second_name = 'Group2',
sep_val = " vs. ", digits = 0, keep_all = TRUE)
paste_tbl_grp(data = descriptive_stats_by_group, vars_to_paste = c("mean", "median_min_max"),
alternative= "less", keep_all = FALSE)
paste_tbl_grp(data = descriptive_stats_by_group, vars_to_paste = 'all',
first_name = 'Group1', second_name = 'Group2', sep_val = " vs. ",
alternative = 'less', digits = 5, keep_all = FALSE)
# Same example with tidyverse (dplyr+tidyr) with some custom functions
library(dplyr)
library(tidyr)
q95_fun = function(x) quantile(x, 0.95)
N = function(x) length(x)
exampleData_BAMA %>%
mutate(group = paste0("Group", group)) %>%
group_by(group, visitno, antigen) %>%
summarise_at("magnitude", funs(N, mean, sd, median, min, max, q95_fun)) %>%
gather(variable, value, -(group:antigen)) %>% # these three chains create a wide dataset
unite(temp, group, variable) %>%
spread(temp, value) %>%
mutate(Group1 = "Group 1", Group2 = "Group 2") %>%
paste_tbl_grp()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.