Skip to contents

This function is a wrapper for easy affixing of the per cent sign (%) to a value or a vector or a data frame of values.

Usage

Percent(Data, Type, format = "f", ...)

Arguments

Data

The Data which the percent sign is to be affixed. The data must be in the raw form for frame argument since the per cent value of each cell is calculated before the sign is affixed.

Type

The type of data. The options for this argument are Value for scalar or vector numeric data or Frame for a numeric vector or data.frame data. In the case of frame, whether vector or columns, the per cent value of each cell is calculated before the per cent sign is affixed.

format

The format of the output which is internal and the default is a character factor

...

Additional arguments that may be passed to the function

Value

This function returns the result as

percent

values with the percentage sign (%) affixed.

Examples

Data <- c(1.2, 0.5, 0.103, 7, 0.1501)
Percent(Data = Data, Type = "Frame")  # Value, Frame
#> $percent
#> [1] "13.4032%" "5.5847%"  "1.1504%"  "78.1852%" "1.6765%" 
#> 
#> $Rate
#> [1] 13.403179  5.584658  1.150440 78.185210  1.676514
#> 
Data <- 1.2
Percent(Data = Data, Type = "Value")  # Value, Frame
#> $percent
#> [1] "1.2%"
#> 
#> $Rate
#> [1] 100
#> 
df <- data.frame(c(A = 2320, 5760, 4800, 2600, 5700, 7800, 3000, 6300, 2400,
10000, 2220, 3740),
B = c(0, 0, 1620, 3600, 1200, 1200, 1200, 4250, 14000, 10000, 1850, 1850),
C = c(3000, 3000, 7800, 5400, 3900, 7800, 1950, 2400, 2400, 7000, 1850, 1850),
D = c(2900, 5760, 3750, 5400, 4095, 3150, 2080, 7800, 1920, 1200, 5000, 1950),
E = c(2900, 2030, 0, 5400, 5760, 1800, 2000, 1950, 1850, 3600, 5200, 5760),
F = c(2800, 5760, 1820, 4340, 7500, 2400, 2300, 1680, 1850, 0, 2800, 8000),
G = c(5760, 4600, 13000, 7800, 6270, 1200, 1440, 8000, 1200, 2025, 4800, 2600),
H = c(2100, 5760, 8250, 3900, 1800, 1200, 4800, 1800, 7800, 2035, 8000, 3000))
Percent(Data = df, Type = "Frame")  # Value, Frame
#> $percent
#>    c.A...2320..5760..4800..2600..5700..7800..3000..6300..2400..10000..
#> 1                                                    4.09604519774011%
#> 2                                                    10.1694915254237%
#> 3                                                    8.47457627118644%
#> 4                                                    4.59039548022599%
#> 5                                                    10.0635593220339%
#> 6                                                     13.771186440678%
#> 7                                                    5.29661016949153%
#> 8                                                    11.1228813559322%
#> 9                                                    4.23728813559322%
#> 10                                                   17.6553672316384%
#> 11                                                   3.91949152542373%
#> 12                                                   6.60310734463277%
#>                    B                 C                 D                 E
#> 1                 0%  6.2047569803516% 6.44372847461393% 7.58169934640523%
#> 2                 0%  6.2047569803516% 12.7985779357849% 5.30718954248366%
#> 3  3.97350993377483% 16.1323681489142% 8.33240751027664%                0%
#> 4  8.83002207505519% 11.1685625646329% 11.9986668147984% 14.1176470588235%
#> 5  2.94334069168506% 8.06618407445708% 9.09898900122209% 15.0588235294118%
#> 6  2.94334069168506% 16.1323681489142% 6.99922230863237% 4.70588235294118%
#> 7  2.94334069168506% 4.03309203722854% 4.62170869903344% 5.22875816993464%
#> 8  10.4243316163846% 4.96380558428128% 17.3314076213754% 5.09803921568627%
#> 9  34.3389747363257% 4.96380558428128% 4.26619264526164% 4.83660130718954%
#> 10 24.5278390973755% 14.4777662874871% 2.66637040328852% 9.41176470588235%
#> 11 4.53765023301447% 3.82626680455016% 11.1098766803688% 13.5947712418301%
#> 12 4.53765023301447% 3.82626680455016% 4.33285190534385% 15.0588235294118%
#>                    F                 G                 H
#> 1  6.78787878787879% 9.81344237158191% 4.16294974724948%
#> 2  13.9636363636364% 7.83712411619388% 11.4183764495986%
#> 3  4.41212121212121% 22.1483942414175%  16.354445435623%
#> 4  10.5212121212121% 13.2890365448505% 7.73119238774903%
#> 5  18.1818181818182% 10.6823409148991% 3.56824264049955%
#> 6  5.81818181818182% 2.04446716074623%  2.3788284269997%
#> 7  5.57575757575758% 2.45336059289548% 9.51531370799881%
#> 8  4.07272727272727% 13.6297810716415% 3.56824264049955%
#> 9  4.48484848484848% 2.04446716074623% 15.4623847754981%
#> 10                0% 3.45003833375926%   4.034096540787%
#> 11 6.78787878787879% 8.17786864298492%  15.858856179998%
#> 12 19.3939393939394%  4.4296788482835% 5.94707106749926%
#> 
#> $Rate
#>    c.A...2320..5760..4800..2600..5700..7800..3000..6300..2400..10000..
#> 1                                                             4.096045
#> 2                                                            10.169492
#> 3                                                             8.474576
#> 4                                                             4.590395
#> 5                                                            10.063559
#> 6                                                            13.771186
#> 7                                                             5.296610
#> 8                                                            11.122881
#> 9                                                             4.237288
#> 10                                                           17.655367
#> 11                                                            3.919492
#> 12                                                            6.603107
#>            B         C         D         E         F         G         H
#> 1   0.000000  6.204757  6.443728  7.581699  6.787879  9.813442  4.162950
#> 2   0.000000  6.204757 12.798578  5.307190 13.963636  7.837124 11.418376
#> 3   3.973510 16.132368  8.332408  0.000000  4.412121 22.148394 16.354445
#> 4   8.830022 11.168563 11.998667 14.117647 10.521212 13.289037  7.731192
#> 5   2.943341  8.066184  9.098989 15.058824 18.181818 10.682341  3.568243
#> 6   2.943341 16.132368  6.999222  4.705882  5.818182  2.044467  2.378828
#> 7   2.943341  4.033092  4.621709  5.228758  5.575758  2.453361  9.515314
#> 8  10.424332  4.963806 17.331408  5.098039  4.072727 13.629781  3.568243
#> 9  34.338975  4.963806  4.266193  4.836601  4.484848  2.044467 15.462385
#> 10 24.527839 14.477766  2.666370  9.411765  0.000000  3.450038  4.034097
#> 11  4.537650  3.826267 11.109877 13.594771  6.787879  8.177869 15.858856
#> 12  4.537650  3.826267  4.332852 15.058824 19.393939  4.429679  5.947071
#>