f: Binary operator to give format to a number

%f%R Documentation

Binary operator to give format to a number

Description

Binary operator to format a number to be used with the sweep function.

Usage

x 

Arguments

x

A numeric R object

format

A string with a format like "$#,#0,0.-" it will provide a prefix, a suffix, a big mark, a decimal mark and digit number.

Details

The purpose of this function is provide a binary operator to format a number to be used in the function sweep. The string with the format is very similar to the formating string in common spreadsheet software. An example string could be a prefix with a dolar sign: "$0"

Value

Returns a string with the number formated to be printed in a report

Examples

# Add a dollar sign as prefix:
5000 %f% "$0"
# Add a percent sign as suffix:
5000 %f% "0%"
# Use "," as big.mark
5000 %f% "#,#0"
# Use "," as decimal.mark with two digits
pi %f% "0.00"
# Use "$" as prefix, ".-" as suffix, "," as decimal.mark, "." as bigmark with two digits
5000 %f% "$#.#0,00.-"

# Make a matrix with 9 numbers
# Then format the first column with a dollar sign,
# second row with percent sign and thrid surounded with parenthesis.
m <- matrix(seq(10,90, length.out=9), ncol = 3)
sweep(m,2,c("$0","0%","(0)"), "%f%")


andresnecochea/multitabulation documentation built on June 15, 2022, 5:55 a.m.