f_parenthesis: Parenthesis Formatting of Two Vectors

Description Usage Arguments Value Examples

View source: R/f_parenthesis.R

Description

f_parenthesis - Form two vectors of numbers as a leading number followed by a second number in parenthesis.

f_mean_sd - Wrapper for f_parenthesis optimized for formatting vectors of means and standard deviations.

f_num_percent - Wrapper for f_parenthesis optimized for formatting vectors of numbers and percentages deviations.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
f_parenthesis(x, y, sep = "", x_prefix = "", y_prefix = "", ...)

ff_parenthesis(...)

f_mean_sd(x, y, x_digits = 1, y_digits = x_digits, sep = "", ...)

ff_mean_sd(...)

f_num_percent(
  x,
  y,
  x_digits = 1,
  y_digits = x_digits,
  sep = "",
  prop_fun = numform::f_prop2percent,
  ...
)

ff_num_percent(...)

Arguments

x

Vector 1 (in f_mean_sd the mean values and in f_num_percent the leading number vector).

y

Vector 2 (in f_mean_sd the standard deviation values and in f_num_percent the percent/proportion vector).

sep

The separator between the first number and the leading parenthesis.

x_prefix

A constant to place before each value in the x vector.

y_prefix

A constant to place before each value in the y vector inside of the parenthesis.

x_digits

The number of digits to round the x vector.

y_digits

The number of digits to round the y vector.

prop_fun

The proportion function to convert the y y vector in f_num_percent. Default is f_prop2percent. f_percent is used for when the values are already percentages.

...

ignored.

Value

Returns a vector of parenthesis combined strings using vector x and y.

Examples

 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
f_parenthesis(
    f_num(sample(50:100, 5), 1),
    f_num(rnorm(5, 5:15, 5), 1),
    prefix = 'mean = ',
    parenthesis_prefix = 'sd = ',
    sep = " "
)

f_mean_sd(rnorm(5, 100, 20), rnorm(5, 20, 5))

f_num_percent(rnorm(5, 100, 20), rnorm(5, .5, .1))

f_parenthesis(
    sample(50:100, 5),
    f_prop2percent(rnorm(5, .5, .1), 0)
)

 ## Not run: 
library(tidyverse)
mtcars %>%
    group_by(cyl) %>%
    summarize(
        mean = mean(hp),
        sd = sd(hp),
        n = n()
    ) %>%
    mutate(
        prop = n /sum(n),
        mean_sd = f_mean_sd(mean, sd),
        n_perc = f_num_percent(n, prop, 0)
    )

## End(Not run)

numform documentation built on Oct. 10, 2021, 1:10 a.m.