FormatData | R Documentation |
This function is used to produce a string from numbers describing results (value and range) for documents and manuscripts.
FormatData(
estimate,
lower = NA,
upper = NA,
places = NULL,
prefix = "",
suffix = "",
units = "",
rangestr = "",
rangeto = "‒",
rangebracket = c(" (", ")"),
rangeappend = c("single", "both"),
thousands = c(",", " "),
decimal = c("low", "mid"),
tail = ""
)
estimate |
Numeric value we are reporting. |
lower |
Lower value of the number we are reporting. Optional so NULL by default. Can just present the lower bound, e.g., to present "10 (SD 2)" |
upper |
Upper value of the number we are reporting. Optional so NULL by default. |
places |
Integer indicating the number of decimal places (in round). Negative values are allowed and means rounding to a power of ten, so for example round(x, digits = -2) rounds to the nearest hundred. |
prefix |
String to put in front of numbers. Primarily used for adding "$" or "A$" for monetary values. |
suffix |
String to put at the end of numeric values. Primarily used used for adding percent symbol. |
units |
String to place after estimate for units. |
rangestr |
String to put in front of the range. For example "range: ", "95 percent CI: ". |
rangeto |
String to link the lower and upper value in the range. Default is an en-dash but could be ":", " to ", etc. |
rangebracket |
Vector of two string to separate estimate from range. Default is round brackets c(" (",")") but could use other brackets or commas c(", ", ",") or something else. |
rangeappend |
Append prefix and suffix to both lower and upper ("both) or just prefix to lower and suffix to upper ("single"). |
thousands |
String to separate estimates by thousands. Default is a comma "," but can be a space " ". |
decimal |
String to show decimal only does lower or midline. Default is "." but Lancet uses a midline decimal. |
tail |
String to attach to the end of the overall string. NOT sure if this is useful or not. |
The idea of this function is to take a number and range (optional) and put it into the suitable format for writing purposes using the appropriate format, range description, and units.
For specific applications it is useful to right wrapper functions to save having to spell out all the options.
The punctuation generally follows the Lancet style.
String with the estimate and range in appropriate format.
Richard T Gray, Rgray@kirby.unsw.edu.au
FormatData(1951508)
FormatData(1951508, prefix = "US$")
FormatData(36.7858, 5.8124, rangestr = "SD ")
FormatData(36.7858, 5.8124, units = "copies/ml", rangestr = "SD ")
FormatData(1235.45, 179.3, 12707.5, prefix = "A$", rangeappend = "both",
rangeto = " to ", rangestr = "range: ")
FormatData(0.84, 0.71, 0.98, decimal = "mid", rangestr = "95% CI: ")
FormatData(0.84, 0.71, 0.98, rangebracket = c(", ",","),
rangestr = "95% CI: ", tail = paste0(" p=", toString(0.03)))
FormatData(84.3, 72.456, 98.123245, suffix = "%")
FormatData(84.3, 72.456, 98.123245, suffix = "%", units = "per year",
rangeappend = "both", rangeto = " to ")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.