Description Usage Arguments Value See Also Examples
cro_mean
, cro_sum
, cro_median
calculate
mean/sum/median by groups. NA's are always omitted.
cro_mean_sd_n
calculates mean, standard deviation and N
simultaneously. Mainly intended for usage with significance_means.
cro_pearson
, cro_spearman
calculate correlation of
first variable in each data.frame in cell_vars
with other variables.
NA's are removed pairwise.
cro_fun
, cro_fun_df
return table with custom summary
statistics defined by fun
argument. NA's treatment depends on your
fun
behavior. To use weight you should have formal weight
argument in fun
and some logic for its processing inside. Several
functions with weight support are provided  see w_mean.
cro_fun
applies fun
on each variable in cell_vars
separately, cro_fun_df
gives to fun
each data.frame in
cell_vars
as a whole. So cro_fun(iris[, 5], iris$Species, fun =
mean)
gives the same result as cro_fun_df(iris[, 5], iris$Species,
fun = colMeans)
. For cro_fun_df
names of cell_vars
will
converted to labels if they are available before the fun
will be applied.
Generally it is recommended that fun
will always return object of the
same form. Row names/vector names of fun
result will appear in the row
labels of the table and column names/names of list will appear in the column
labels. If your fun
returns data.frame/matrix/list with element named
'row_labels' then this element will be used as row labels. And it will have
precedence over rownames.
calc_cro_*
are the same as above but evaluate their arguments
in the context of the first argument data
.
combine_functions
is auxiliary function for combining several
functions into one function for usage with cro_fun
/cro_fun_df
.
Names of arguments will be used as statistic labels. By default, results of
each function are combined with c. But you can provide your own method
function with method
argument. It will be applied as in the expression
do.call(method, list_of_functions_results)
. Particular useful method
is list
. When it used then statistic labels will appear in the column
labels. See examples. Also you may be interested in data.frame
,
rbind
, cbind
methods.
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153  cro_fun(
cell_vars,
col_vars = total(),
row_vars = total(label = ""),
weight = NULL,
subgroup = NULL,
fun,
...,
unsafe = FALSE
)
cro_fun_df(
cell_vars,
col_vars = total(),
row_vars = total(label = ""),
weight = NULL,
subgroup = NULL,
fun,
...,
unsafe = FALSE
)
cro_mean(
cell_vars,
col_vars = total(),
row_vars = total(label = ""),
weight = NULL,
subgroup = NULL
)
cro_mean_sd_n(
cell_vars,
col_vars = total(),
row_vars = total(label = ""),
weight = NULL,
subgroup = NULL,
weighted_valid_n = FALSE,
labels = NULL
)
cro_sum(
cell_vars,
col_vars = total(),
row_vars = total(label = ""),
weight = NULL,
subgroup = NULL
)
cro_median(
cell_vars,
col_vars = total(),
row_vars = total(label = ""),
weight = NULL,
subgroup = NULL
)
cro_pearson(
cell_vars,
col_vars = total(),
row_vars = total(label = ""),
weight = NULL,
subgroup = NULL
)
cro_spearman(
cell_vars,
col_vars = total(),
row_vars = total(label = ""),
weight = NULL,
subgroup = NULL
)
calc_cro_fun(
data,
cell_vars,
col_vars = total(),
row_vars = total(label = ""),
weight = NULL,
subgroup = NULL,
fun,
...,
unsafe = FALSE
)
calc_cro_fun_df(
data,
cell_vars,
col_vars = total(),
row_vars = total(label = ""),
weight = NULL,
subgroup = NULL,
fun,
...,
unsafe = FALSE
)
calc_cro_mean(
data,
cell_vars,
col_vars = total(),
row_vars = total(label = ""),
weight = NULL,
subgroup = NULL
)
calc_cro_mean_sd_n(
data,
cell_vars,
col_vars = total(),
row_vars = total(label = ""),
weight = NULL,
subgroup = NULL,
weighted_valid_n = FALSE,
labels = NULL
)
calc_cro_sum(
data,
cell_vars,
col_vars = total(),
row_vars = total(label = ""),
weight = NULL,
subgroup = NULL
)
calc_cro_median(
data,
cell_vars,
col_vars = total(),
row_vars = total(label = ""),
weight = NULL,
subgroup = NULL
)
calc_cro_pearson(
data,
cell_vars,
col_vars = total(),
row_vars = total(label = ""),
weight = NULL,
subgroup = NULL
)
calc_cro_spearman(
data,
cell_vars,
col_vars = total(),
row_vars = total(label = ""),
weight = NULL,
subgroup = NULL
)
combine_functions(..., method = c)

cell_vars 
vector/data.frame/list. Variables on which summary function will be computed. 
col_vars 
vector/data.frame/list. Variables which breaks table by columns. Use mrset/mdset for multipleresponse variables. 
row_vars 
vector/data.frame/list. Variables which breaks table by rows. Use mrset/mdset for multipleresponse variables. 
weight 
numeric vector. Optional cases weights. Cases with NA's, negative and zero weights are removed before calculations. 
subgroup 
logical vector. You can specify subgroup on which table will be computed. 
fun 
custom summary function. Generally it is recommended that

... 
further arguments for 
unsafe 
logical/character If not FALSE than 
weighted_valid_n 
logical. Should we show weighted valid N in

labels 
character vector of length 3. Labels for mean, standard
deviation and valid N in 
data 
data.frame in which context all other arguments will be evaluated
(for 
method 
function which will combine results of multiple functions in

object of class 'etable'. Basically it's a data.frame but class is needed for custom methods.
tables, fre, cro.
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98  data(mtcars)
mtcars = apply_labels(mtcars,
mpg = "Miles/(US) gallon",
cyl = "Number of cylinders",
disp = "Displacement (cu.in.)",
hp = "Gross horsepower",
drat = "Rear axle ratio",
wt = "Weight (1000 lbs)",
qsec = "1/4 mile time",
vs = "Engine",
vs = c("Vengine" = 0,
"Straight engine" = 1),
am = "Transmission",
am = c("Automatic" = 0,
"Manual"=1),
gear = "Number of forward gears",
carb = "Number of carburetors"
)
# Simple example  there is special shortcut for it  'cro_mean'
calculate(mtcars, cro_fun(list(mpg, disp, hp, wt, qsec),
col_vars = list(total(), am),
row_vars = vs,
fun = mean)
)
# the same result
calc_cro_fun(mtcars, list(mpg, disp, hp, wt, qsec),
col_vars = list(total(), am),
row_vars = vs,
fun = mean
)
# The same example with 'subgroup'
calculate(mtcars, cro_fun(list(mpg, disp, hp, wt, qsec),
col_vars = list(total(), am),
row_vars = vs,
subgroup = vs == 0,
fun = mean)
)
# 'combine_functions' usage
calculate(mtcars, cro_fun(list(mpg, disp, hp, wt, qsec),
col_vars = list(total(), am),
row_vars = vs,
fun = combine_functions(Mean = mean,
'Std. dev.' = sd,
'Valid N' = valid_n)
))
# 'combine_functions' usage  statistic labels in columns
calculate(mtcars, cro_fun(list(mpg, disp, hp, wt, qsec),
col_vars = list(total(), am),
row_vars = vs,
fun = combine_functions(Mean = mean,
'Std. dev.' = sd,
'Valid N' = valid_n,
method = list
)
))
# 'summary' function
calculate(mtcars, cro_fun(list(mpg, disp, hp, wt, qsec),
col_vars = list(total(), am),
row_vars = list(total(), vs),
fun = summary
))
# comparison 'cro_fun' and 'cro_fun_df'
calculate(mtcars, cro_fun(
sheet(mpg, disp, hp, wt, qsec),
col_vars = am,
fun = mean
)
)
# same result
calculate(mtcars, cro_fun_df(
sheet(mpg, disp, hp, wt, qsec),
col_vars = am,
fun = colMeans
)
)
# usage for 'cro_fun_df' which is not possible for 'cro_fun'
# linear regression by groups
calculate(mtcars, cro_fun_df(
sheet(mpg, disp, hp, wt, qsec),
col_vars = am,
fun = function(x){
frm = reformulate(".", response = names(x)[1])
model = lm(frm, data = x)
sheet(
'Coef. estimate' = coef(model),
confint(model)
)
}
))

    #Total  Transmission 
     Automatic 
          
 Engine  Vengine  Miles/(US) gallon  16.6  15.1 
   Displacement (cu.in.)  307.1  357.6 
   Gross horsepower  189.7  194.2 
   Weight (1000 lbs)  3.7  4.1 
   1/4 mile time  16.7  17.1 
  Straight engine  Miles/(US) gallon  24.6  20.7 
   Displacement (cu.in.)  132.5  175.1 
   Gross horsepower  91.4  102.1 
   Weight (1000 lbs)  2.6  3.2 
   1/4 mile time  19.3  20.0 

Manual 
 
19.8 
206.2 
180.8 
2.9 
15.8 
28.4 
89.8 
80.6 
2.0 
18.7 
    #Total  Transmission 
     Automatic 
          
 Engine  Vengine  Miles/(US) gallon  16.6  15.1 
   Displacement (cu.in.)  307.1  357.6 
   Gross horsepower  189.7  194.2 
   Weight (1000 lbs)  3.7  4.1 
   1/4 mile time  16.7  17.1 
  Straight engine  Miles/(US) gallon  24.6  20.7 
   Displacement (cu.in.)  132.5  175.1 
   Gross horsepower  91.4  102.1 
   Weight (1000 lbs)  2.6  3.2 
   1/4 mile time  19.3  20.0 

Manual 
 
19.8 
206.2 
180.8 
2.9 
15.8 
28.4 
89.8 
80.6 
2.0 
18.7 
    #Total  Transmission 
     Automatic 
          
 Engine  Vengine  Miles/(US) gallon  16.6  15.1 
   Displacement (cu.in.)  307.1  357.6 
   Gross horsepower  189.7  194.2 
   Weight (1000 lbs)  3.7  4.1 
   1/4 mile time  16.7  17.1 
  Straight engine  Miles/(US) gallon   
   Displacement (cu.in.)   
   Gross horsepower   
   Weight (1000 lbs)   
   1/4 mile time   

Manual 
 
19.8 
206.2 
180.8 
2.9 
15.8 





     #Total 
     
          
 Engine  Vengine  Miles/(US) gallon  Mean  16.6 
    Std. dev.  3.9 
    Valid N  18.0 
   Displacement (cu.in.)  Mean  307.1 
    Std. dev.  106.8 
    Valid N  18.0 
   Gross horsepower  Mean  189.7 
    Std. dev.  60.3 
    Valid N  18.0 
   Weight (1000 lbs)  Mean  3.7 
    Std. dev.  0.9 
    Valid N  18.0 
   1/4 mile time  Mean  16.7 
    Std. dev.  1.1 
    Valid N  18.0 
  Straight engine  Miles/(US) gallon  Mean  24.6 
    Std. dev.  5.4 
    Valid N  14.0 
   Displacement (cu.in.)  Mean  132.5 
    Std. dev.  56.9 
    Valid N  14.0 
   Gross horsepower  Mean  91.4 
    Std. dev.  24.4 
    Valid N  14.0 
   Weight (1000 lbs)  Mean  2.6 
    Std. dev.  0.7 
    Valid N  14.0 
   1/4 mile time  Mean  19.3 
    Std. dev.  1.4 
    Valid N  14.0 
Transmission  
Automatic  Manual 
   
15.1  19.8 
2.8  4.0 
12.0  6.0 
357.6  206.2 
71.8  95.2 
12.0  6.0 
194.2  180.8 
33.4  98.8 
12.0  6.0 
4.1  2.9 
0.8  0.5 
12.0  6.0 
17.1  15.8 
0.8  1.1 
12.0  6.0 
20.7  28.4 
2.5  4.8 
7.0  7.0 
175.1  89.8 
49.1  18.8 
7.0  7.0 
102.1  80.6 
20.9  24.1 
7.0  7.0 
3.2  2.0 
0.3  0.4 
7.0  7.0 
20.0  18.7 
1.5  0.9 
7.0  7.0 
    #Total  
    Mean  Std. dev. 
     
          
 Engine  Vengine  Miles/(US) gallon  16.6  3.9 
   Displacement (cu.in.)  307.1  106.8 
   Gross horsepower  189.7  60.3 
   Weight (1000 lbs)  3.7  0.9 
   1/4 mile time  16.7  1.1 
  Straight engine  Miles/(US) gallon  24.6  5.4 
   Displacement (cu.in.)  132.5  56.9 
   Gross horsepower  91.4  24.4 
   Weight (1000 lbs)  2.6  0.7 
   1/4 mile time  19.3  1.4 
 Transmission      
Valid N  Automatic    Manual   
 Mean  Std. dev.  Valid N  Mean  Std. dev.  Valid N 
             
18  15.1  2.8  12  19.8  4.0  6 
18  357.6  71.8  12  206.2  95.2  6 
18  194.2  33.4  12  180.8  98.8  6 
18  4.1  0.8  12  2.9  0.5  6 
18  17.1  0.8  12  15.8  1.1  6 
14  20.7  2.5  7  28.4  4.8  7 
14  175.1  49.1  7  89.8  18.8  7 
14  102.1  20.9  7  80.6  24.1  7 
14  3.2  0.3  7  2.0  0.4  7 
14  20.0  1.5  7  18.7  0.9  7 
     #Total 
     
          
 #Total  Miles/(US) gallon  Min.   10.4 
   1st Qu.   15.4 
   Median   19.2 
   Mean   20.1 
   3rd Qu.   22.8 
   Max.   33.9 
  Displacement (cu.in.)  Min.   71.1 
   1st Qu.   120.8 
   Median   196.3 
   Mean   230.7 
   3rd Qu.   326.0 
   Max.   472.0 
  Gross horsepower  Min.   52.0 
   1st Qu.   96.5 
   Median   123.0 
   Mean   146.7 
   3rd Qu.   180.0 
   Max.   335.0 
  Weight (1000 lbs)  Min.   1.5 
   1st Qu.   2.6 
   Median   3.3 
   Mean   3.2 
   3rd Qu.   3.6 
   Max.   5.4 
  1/4 mile time  Min.   14.5 
   1st Qu.   16.9 
   Median   17.7 
   Mean   17.8 
   3rd Qu.   18.9 
   Max.   22.9 
 Engine  Vengine  Miles/(US) gallon  Min.  10.4 
    1st Qu.  14.8 
    Median  15.7 
    Mean  16.6 
    3rd Qu.  19.1 
    Max.  26.0 
   Displacement (cu.in.)  Min.  120.3 
    1st Qu.  275.8 
    Median  311.0 
    Mean  307.1 
    3rd Qu.  360.0 
    Max.  472.0 
   Gross horsepower  Min.  91.0 
    1st Qu.  156.2 
    Median  180.0 
    Mean  189.7 
    3rd Qu.  226.2 
    Max.  335.0 
   Weight (1000 lbs)  Min.  2.1 
    1st Qu.  3.2 
    Median  3.6 
    Mean  3.7 
    3rd Qu.  3.8 
    Max.  5.4 
   1/4 mile time  Min.  14.5 
    1st Qu.  16.0 
    Median  17.0 
    Mean  16.7 
    3rd Qu.  17.4 
    Max.  18.0 
  Straight engine  Miles/(US) gallon  Min.  17.8 
    1st Qu.  21.4 
    Median  22.8 
    Mean  24.6 
    3rd Qu.  29.6 
    Max.  33.9 
   Displacement (cu.in.)  Min.  71.1 
    1st Qu.  83.0 
    Median  120.5 
    Mean  132.5 
    3rd Qu.  162.4 
    Max.  258.0 
   Gross horsepower  Min.  52.0 
    1st Qu.  66.0 
    Median  96.0 
    Mean  91.4 
    3rd Qu.  109.8 
    Max.  123.0 
   Weight (1000 lbs)  Min.  1.5 
    1st Qu.  2.0 
    Median  2.6 
    Mean  2.6 
    3rd Qu.  3.2 
    Max.  3.5 
   1/4 mile time  Min.  16.9 
    1st Qu.  18.6 
    Median  19.2 
    Mean  19.3 
    3rd Qu.  20.0 
    Max.  22.9 
Transmission  
Automatic  Manual 
   
10.4  15.0 
14.9  21.0 
17.3  22.8 
17.1  24.4 
19.2  30.4 
24.4  33.9 
120.1  71.1 
196.3  79.0 
275.8  120.3 
290.4  143.5 
360.0  160.0 
472.0  351.0 
62.0  52.0 
116.5  66.0 
175.0  109.0 
160.3  126.8 
192.5  113.0 
245.0  335.0 
2.5  1.5 
3.4  1.9 
3.5  2.3 
3.8  2.4 
3.8  2.8 
5.4  3.6 
15.4  14.5 
17.2  16.5 
17.8  17.0 
18.2  17.4 
19.2  18.6 
22.9  19.9 
10.4  15.0 
14.1  16.8 
15.2  20.4 
15.1  19.8 
16.6  21.0 
19.2  26.0 
275.8  120.3 
296.9  148.8 
355.0  160.0 
357.6  206.2 
410.0  265.8 
472.0  351.0 
150.0  91.0 
175.0  110.0 
180.0  142.5 
194.2  180.8 
218.8  241.8 
245.0  335.0 
3.4  2.1 
3.6  2.7 
3.8  2.8 
4.1  2.9 
4.4  3.1 
5.4  3.6 
15.4  14.5 
17.0  14.8 
17.4  16.0 
17.1  15.8 
17.7  16.6 
18.0  17.0 
17.8  21.4 
18.6  25.1 
21.4  30.4 
20.7  28.4 
22.1  31.4 
24.4  33.9 
120.1  71.1 
143.8  77.2 
167.6  79.0 
175.1  89.8 
196.3  101.5 
258.0  121.0 
62.0  52.0 
96.0  65.5 
105.0  66.0 
102.1  80.6 
116.5  101.0 
123.0  113.0 
2.5  1.5 
3.2  1.7 
3.2  1.9 
3.2  2.0 
3.4  2.3 
3.5  2.8 
18.3  16.9 
19.2  18.6 
20.0  18.6 
20.0  18.7 
20.1  19.2 
22.9  19.9 
  Transmission  
  Automatic  Manual 
      
 Miles/(US) gallon  17.1  24.4 
 Displacement (cu.in.)  290.4  143.5 
 Gross horsepower  160.3  126.8 
 Weight (1000 lbs)  3.8  2.4 
 1/4 mile time  18.2  17.4 
  Transmission  
  Automatic  Manual 
      
 Miles/(US) gallon  17.1  24.4 
 Displacement (cu.in.)  290.4  143.5 
 Gross horsepower  160.3  126.8 
 Weight (1000 lbs)  3.8  2.4 
 1/4 mile time  18.2  17.4 
  Transmission    
  Automatic    Manual 
  Coef. estimate  2.5 %  97.5 %  Coef. estimate 
          
 (Intercept)  21.8  1.9  45.5  13.3 
 `Displacement (cu.in.)`  0.0  0.0  0.0  0.0 
 `Gross horsepower`  0.0  0.1  0.0  0.0 
 `Weight (1000 lbs)`  2.3  5.0  0.4  7.7 
 `1/4 mile time`  0.4  0.7  1.6  1.6 
 
 
2.5 %  97.5 % 
   
21.9  48.4 
0.1  0.1 
0.0  0.1 
12.5  2.9 
0.2  3.4 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.