Learn R Programming

numform (version 0.6.4)

f_parenthesis: Parenthesis Formatting of Two Vectors

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

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

Run this code
# NOT RUN {
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)
    )
# }

Run the code above in your browser using DataLab