numform (version 0.5.0)

fv_percent_diff: Percent Difference

Description

fv_percent_diff - Convert a vector of values to percent differences (i.e., (T2 - T1)/T1).

Usage

fv_percent_diff(x, digits = getOption("numformdigits"), ...)

fv_percent_diff_fixed_relative(x, fixed.relative = 1, digits = getOption("numformdigits"), ...)

ffv_percent_diff_fixed_relative(...)

ffv_percent_diff(...)

Arguments

x

A numeric vector.

digits

The number of digits to use. Defaults to 1. Can be set globally via: options(numformdigits = n) where n is the number of digits beyond the decimal point to include.

fixed.relative

The position of the element to be used for comparison. Default is the first element.

Other arguments passed to f_prop2percent.

Value

Returns a string of publication ready relative percent differences.

Examples

Run this code
# NOT RUN {
set.seed(10)
x <- sample(1:10)

data.frame(
    original = x,
    perc_change = fv_percent_diff(x)
)

# }
# NOT RUN {
library(dplyr)

CO2 %>%
    group_by(Plant) %>%
    mutate(
        `Percent` = fv_percent(conc),
        `Percent Diff` = fv_percent_diff(conc)
    ) %>%
    print(n=Inf)

CO2 %>%
    group_by(Type, Treatment) %>%
    mutate(
        `Percent` = fv_percent(conc),
        `Percent Diff` = fv_percent_diff(conc)
    ) %>%
    print(n=Inf)
# }

Run the code above in your browser using DataLab