fv_percent_diff: Percent Difference

Description Usage Arguments Value Examples

View source: R/fv_percent_diff.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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

 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
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)

## End(Not run)

Example output

   original perc_change
1         6         .0%
2         3      -50.0%
3         4       33.3%
4         5       25.0%
5         1      -80.0%
6         2      100.0%
7         7      250.0%
8        10       42.9%
9         8      -20.0%
10        9       12.5%

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

# A tibble: 84 x 7
# Groups:   Plant [12]
   Plant        Type  Treatment  conc uptake Percent `Percent Diff`
   <ord>      <fctr>     <fctr> <dbl>  <dbl>   <chr>          <chr>
 1   Qn1      Quebec nonchilled    95   16.0    3.1%            .0%
 2   Qn1      Quebec nonchilled   175   30.4    5.7%          84.2%
 3   Qn1      Quebec nonchilled   250   34.8    8.2%          42.9%
 4   Qn1      Quebec nonchilled   350   37.2   11.5%          40.0%
 5   Qn1      Quebec nonchilled   500   35.3   16.4%          42.9%
 6   Qn1      Quebec nonchilled   675   39.2   22.2%          35.0%
 7   Qn1      Quebec nonchilled  1000   39.7   32.8%          48.1%
 8   Qn2      Quebec nonchilled    95   13.6    3.1%            .0%
 9   Qn2      Quebec nonchilled   175   27.3    5.7%          84.2%
10   Qn2      Quebec nonchilled   250   37.1    8.2%          42.9%
11   Qn2      Quebec nonchilled   350   41.8   11.5%          40.0%
12   Qn2      Quebec nonchilled   500   40.6   16.4%          42.9%
13   Qn2      Quebec nonchilled   675   41.4   22.2%          35.0%
14   Qn2      Quebec nonchilled  1000   44.3   32.8%          48.1%
15   Qn3      Quebec nonchilled    95   16.2    3.1%            .0%
16   Qn3      Quebec nonchilled   175   32.4    5.7%          84.2%
17   Qn3      Quebec nonchilled   250   40.3    8.2%          42.9%
18   Qn3      Quebec nonchilled   350   42.1   11.5%          40.0%
19   Qn3      Quebec nonchilled   500   42.9   16.4%          42.9%
20   Qn3      Quebec nonchilled   675   43.9   22.2%          35.0%
21   Qn3      Quebec nonchilled  1000   45.5   32.8%          48.1%
22   Qc1      Quebec    chilled    95   14.2    3.1%            .0%
23   Qc1      Quebec    chilled   175   24.1    5.7%          84.2%
24   Qc1      Quebec    chilled   250   30.3    8.2%          42.9%
25   Qc1      Quebec    chilled   350   34.6   11.5%          40.0%
26   Qc1      Quebec    chilled   500   32.5   16.4%          42.9%
27   Qc1      Quebec    chilled   675   35.4   22.2%          35.0%
28   Qc1      Quebec    chilled  1000   38.7   32.8%          48.1%
29   Qc2      Quebec    chilled    95    9.3    3.1%            .0%
30   Qc2      Quebec    chilled   175   27.3    5.7%          84.2%
31   Qc2      Quebec    chilled   250   35.0    8.2%          42.9%
32   Qc2      Quebec    chilled   350   38.8   11.5%          40.0%
33   Qc2      Quebec    chilled   500   38.6   16.4%          42.9%
34   Qc2      Quebec    chilled   675   37.5   22.2%          35.0%
35   Qc2      Quebec    chilled  1000   42.4   32.8%          48.1%
36   Qc3      Quebec    chilled    95   15.1    3.1%            .0%
37   Qc3      Quebec    chilled   175   21.0    5.7%          84.2%
38   Qc3      Quebec    chilled   250   38.1    8.2%          42.9%
39   Qc3      Quebec    chilled   350   34.0   11.5%          40.0%
40   Qc3      Quebec    chilled   500   38.9   16.4%          42.9%
41   Qc3      Quebec    chilled   675   39.6   22.2%          35.0%
42   Qc3      Quebec    chilled  1000   41.4   32.8%          48.1%
43   Mn1 Mississippi nonchilled    95   10.6    3.1%            .0%
44   Mn1 Mississippi nonchilled   175   19.2    5.7%          84.2%
45   Mn1 Mississippi nonchilled   250   26.2    8.2%          42.9%
46   Mn1 Mississippi nonchilled   350   30.0   11.5%          40.0%
47   Mn1 Mississippi nonchilled   500   30.9   16.4%          42.9%
48   Mn1 Mississippi nonchilled   675   32.4   22.2%          35.0%
49   Mn1 Mississippi nonchilled  1000   35.5   32.8%          48.1%
50   Mn2 Mississippi nonchilled    95   12.0    3.1%            .0%
51   Mn2 Mississippi nonchilled   175   22.0    5.7%          84.2%
52   Mn2 Mississippi nonchilled   250   30.6    8.2%          42.9%
53   Mn2 Mississippi nonchilled   350   31.8   11.5%          40.0%
54   Mn2 Mississippi nonchilled   500   32.4   16.4%          42.9%
55   Mn2 Mississippi nonchilled   675   31.1   22.2%          35.0%
56   Mn2 Mississippi nonchilled  1000   31.5   32.8%          48.1%
57   Mn3 Mississippi nonchilled    95   11.3    3.1%            .0%
58   Mn3 Mississippi nonchilled   175   19.4    5.7%          84.2%
59   Mn3 Mississippi nonchilled   250   25.8    8.2%          42.9%
60   Mn3 Mississippi nonchilled   350   27.9   11.5%          40.0%
61   Mn3 Mississippi nonchilled   500   28.5   16.4%          42.9%
62   Mn3 Mississippi nonchilled   675   28.1   22.2%          35.0%
63   Mn3 Mississippi nonchilled  1000   27.8   32.8%          48.1%
64   Mc1 Mississippi    chilled    95   10.5    3.1%            .0%
65   Mc1 Mississippi    chilled   175   14.9    5.7%          84.2%
66   Mc1 Mississippi    chilled   250   18.1    8.2%          42.9%
67   Mc1 Mississippi    chilled   350   18.9   11.5%          40.0%
68   Mc1 Mississippi    chilled   500   19.5   16.4%          42.9%
69   Mc1 Mississippi    chilled   675   22.2   22.2%          35.0%
70   Mc1 Mississippi    chilled  1000   21.9   32.8%          48.1%
71   Mc2 Mississippi    chilled    95    7.7    3.1%            .0%
72   Mc2 Mississippi    chilled   175   11.4    5.7%          84.2%
73   Mc2 Mississippi    chilled   250   12.3    8.2%          42.9%
74   Mc2 Mississippi    chilled   350   13.0   11.5%          40.0%
75   Mc2 Mississippi    chilled   500   12.5   16.4%          42.9%
76   Mc2 Mississippi    chilled   675   13.7   22.2%          35.0%
77   Mc2 Mississippi    chilled  1000   14.4   32.8%          48.1%
78   Mc3 Mississippi    chilled    95   10.6    3.1%            .0%
79   Mc3 Mississippi    chilled   175   18.0    5.7%          84.2%
80   Mc3 Mississippi    chilled   250   17.9    8.2%          42.9%
81   Mc3 Mississippi    chilled   350   17.9   11.5%          40.0%
82   Mc3 Mississippi    chilled   500   17.9   16.4%          42.9%
83   Mc3 Mississippi    chilled   675   18.9   22.2%          35.0%
84   Mc3 Mississippi    chilled  1000   19.9   32.8%          48.1%
# A tibble: 84 x 7
# Groups:   Type, Treatment [4]
   Plant        Type  Treatment  conc uptake Percent `Percent Diff`
   <ord>      <fctr>     <fctr> <dbl>  <dbl>   <chr>          <chr>
 1   Qn1      Quebec nonchilled    95   16.0    1.0%            .0%
 2   Qn1      Quebec nonchilled   175   30.4    1.9%          84.2%
 3   Qn1      Quebec nonchilled   250   34.8    2.7%          42.9%
 4   Qn1      Quebec nonchilled   350   37.2    3.8%          40.0%
 5   Qn1      Quebec nonchilled   500   35.3    5.5%          42.9%
 6   Qn1      Quebec nonchilled   675   39.2    7.4%          35.0%
 7   Qn1      Quebec nonchilled  1000   39.7   10.9%          48.1%
 8   Qn2      Quebec nonchilled    95   13.6    1.0%         -90.5%
 9   Qn2      Quebec nonchilled   175   27.3    1.9%          84.2%
10   Qn2      Quebec nonchilled   250   37.1    2.7%          42.9%
11   Qn2      Quebec nonchilled   350   41.8    3.8%          40.0%
12   Qn2      Quebec nonchilled   500   40.6    5.5%          42.9%
13   Qn2      Quebec nonchilled   675   41.4    7.4%          35.0%
14   Qn2      Quebec nonchilled  1000   44.3   10.9%          48.1%
15   Qn3      Quebec nonchilled    95   16.2    1.0%         -90.5%
16   Qn3      Quebec nonchilled   175   32.4    1.9%          84.2%
17   Qn3      Quebec nonchilled   250   40.3    2.7%          42.9%
18   Qn3      Quebec nonchilled   350   42.1    3.8%          40.0%
19   Qn3      Quebec nonchilled   500   42.9    5.5%          42.9%
20   Qn3      Quebec nonchilled   675   43.9    7.4%          35.0%
21   Qn3      Quebec nonchilled  1000   45.5   10.9%          48.1%
22   Qc1      Quebec    chilled    95   14.2    1.0%            .0%
23   Qc1      Quebec    chilled   175   24.1    1.9%          84.2%
24   Qc1      Quebec    chilled   250   30.3    2.7%          42.9%
25   Qc1      Quebec    chilled   350   34.6    3.8%          40.0%
26   Qc1      Quebec    chilled   500   32.5    5.5%          42.9%
27   Qc1      Quebec    chilled   675   35.4    7.4%          35.0%
28   Qc1      Quebec    chilled  1000   38.7   10.9%          48.1%
29   Qc2      Quebec    chilled    95    9.3    1.0%         -90.5%
30   Qc2      Quebec    chilled   175   27.3    1.9%          84.2%
31   Qc2      Quebec    chilled   250   35.0    2.7%          42.9%
32   Qc2      Quebec    chilled   350   38.8    3.8%          40.0%
33   Qc2      Quebec    chilled   500   38.6    5.5%          42.9%
34   Qc2      Quebec    chilled   675   37.5    7.4%          35.0%
35   Qc2      Quebec    chilled  1000   42.4   10.9%          48.1%
36   Qc3      Quebec    chilled    95   15.1    1.0%         -90.5%
37   Qc3      Quebec    chilled   175   21.0    1.9%          84.2%
38   Qc3      Quebec    chilled   250   38.1    2.7%          42.9%
39   Qc3      Quebec    chilled   350   34.0    3.8%          40.0%
40   Qc3      Quebec    chilled   500   38.9    5.5%          42.9%
41   Qc3      Quebec    chilled   675   39.6    7.4%          35.0%
42   Qc3      Quebec    chilled  1000   41.4   10.9%          48.1%
43   Mn1 Mississippi nonchilled    95   10.6    1.0%            .0%
44   Mn1 Mississippi nonchilled   175   19.2    1.9%          84.2%
45   Mn1 Mississippi nonchilled   250   26.2    2.7%          42.9%
46   Mn1 Mississippi nonchilled   350   30.0    3.8%          40.0%
47   Mn1 Mississippi nonchilled   500   30.9    5.5%          42.9%
48   Mn1 Mississippi nonchilled   675   32.4    7.4%          35.0%
49   Mn1 Mississippi nonchilled  1000   35.5   10.9%          48.1%
50   Mn2 Mississippi nonchilled    95   12.0    1.0%         -90.5%
51   Mn2 Mississippi nonchilled   175   22.0    1.9%          84.2%
52   Mn2 Mississippi nonchilled   250   30.6    2.7%          42.9%
53   Mn2 Mississippi nonchilled   350   31.8    3.8%          40.0%
54   Mn2 Mississippi nonchilled   500   32.4    5.5%          42.9%
55   Mn2 Mississippi nonchilled   675   31.1    7.4%          35.0%
56   Mn2 Mississippi nonchilled  1000   31.5   10.9%          48.1%
57   Mn3 Mississippi nonchilled    95   11.3    1.0%         -90.5%
58   Mn3 Mississippi nonchilled   175   19.4    1.9%          84.2%
59   Mn3 Mississippi nonchilled   250   25.8    2.7%          42.9%
60   Mn3 Mississippi nonchilled   350   27.9    3.8%          40.0%
61   Mn3 Mississippi nonchilled   500   28.5    5.5%          42.9%
62   Mn3 Mississippi nonchilled   675   28.1    7.4%          35.0%
63   Mn3 Mississippi nonchilled  1000   27.8   10.9%          48.1%
64   Mc1 Mississippi    chilled    95   10.5    1.0%            .0%
65   Mc1 Mississippi    chilled   175   14.9    1.9%          84.2%
66   Mc1 Mississippi    chilled   250   18.1    2.7%          42.9%
67   Mc1 Mississippi    chilled   350   18.9    3.8%          40.0%
68   Mc1 Mississippi    chilled   500   19.5    5.5%          42.9%
69   Mc1 Mississippi    chilled   675   22.2    7.4%          35.0%
70   Mc1 Mississippi    chilled  1000   21.9   10.9%          48.1%
71   Mc2 Mississippi    chilled    95    7.7    1.0%         -90.5%
72   Mc2 Mississippi    chilled   175   11.4    1.9%          84.2%
73   Mc2 Mississippi    chilled   250   12.3    2.7%          42.9%
74   Mc2 Mississippi    chilled   350   13.0    3.8%          40.0%
75   Mc2 Mississippi    chilled   500   12.5    5.5%          42.9%
76   Mc2 Mississippi    chilled   675   13.7    7.4%          35.0%
77   Mc2 Mississippi    chilled  1000   14.4   10.9%          48.1%
78   Mc3 Mississippi    chilled    95   10.6    1.0%         -90.5%
79   Mc3 Mississippi    chilled   175   18.0    1.9%          84.2%
80   Mc3 Mississippi    chilled   250   17.9    2.7%          42.9%
81   Mc3 Mississippi    chilled   350   17.9    3.8%          40.0%
82   Mc3 Mississippi    chilled   500   17.9    5.5%          42.9%
83   Mc3 Mississippi    chilled   675   18.9    7.4%          35.0%
84   Mc3 Mississippi    chilled  1000   19.9   10.9%          48.1%

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