Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

txtRound

A convenient rounding function


Description

If you provide a string value in X the function will try to round this if a numeric text is present. If you want to skip certain rows/columns then use the excl.* arguments.

Usage

txtRound(x, ...)

## Default S3 method:
txtRound(
  x,
  digits = 0,
  digits.nonzero = NA,
  txt.NA = "",
  dec = getOption("htmlTable.decimal_marker", default = "."),
  scientific = NULL,
  txtInt_args = getOption("htmlTable.round_int", default = NULL),
  ...
)

## S3 method for class 'data.frame'
txtRound(x, ...)

## S3 method for class 'table'
txtRound(x, ...)

## S3 method for class 'matrix'
txtRound(x, digits = 0, excl.cols = NULL, excl.rows = NULL, ...)

Arguments

x

The value/vector/data.frame/matrix to be rounded

...

Passed to next method

digits

The number of digits to round each element to. If you provide a vector each element will apply to the corresponding columns.

digits.nonzero

The number of digits to keep if the result is close to zero. Sometimes we have an entire table with large numbers only to have a few but interesting observation that are really interesting

txt.NA

The string to exchange NA with

dec

The decimal marker. If the text is in non-English decimal and string formatted you need to change this to the appropriate decimal indicator. The option for this is htmlTable.decimal_marker.

scientific

If the value should be in scientific format.

txtInt_args

A list of arguments to pass to txtInt() if that is to be used for large values that may require a thousands separator. The option for this is htmlTable.round_int.

excl.cols

Columns to exclude from the rounding procedure. This can be either a number or regular expression. Skipped if x is a vector.

excl.rows

Rows to exclude from the rounding procedure. This can be either a number or regular expression.

Value

matrix/data.frame

See Also

Other text formatters: txtInt(), txtMergeLines(), txtPval()

Examples

mx <- matrix(c(1, 1.11, 1.25,
               2.50, 2.55, 2.45,
               3.2313, 3, pi),
             ncol = 3, byrow=TRUE)
txtRound(mx, 1)

htmlTable

Advanced Tables for Markdown/HTML

v2.1.0
GPL (>= 3)
Authors
Max Gordon [aut, cre], Stephen Gragg [aut], Peter Konings [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.