format {tutoR}R Documentation

Display a number with a given number of decimal places

Description

Format a number for pretty printing - tutoR mask.

Usage

format(x, digits=0, width=0, justify="right", ...)

Arguments

x any numeric value.
digits number of digits to appear to the right of the decimal point.
width number of character spaces the number is to be aligned in, where a width of 0 procuces a number necessarily left justified.
justify should the final character vector be "right"-justified (the default), "left"-justified or "centre" aligned.
... Additional inputs to format.default, called on appropriately.

Details

The tutoR function, format, masks format from base, with format.default preserved.

Value

A string with the number in the desired format.

See Also

format.default, formatC, paste, as.character, sprintf, print, toString, encodeString.

Examples

format(1:10, 2)

## use of nsmall
format(13.7)
format.default(13.7, nsmall = 3)
format(c(6.0, 13.1), digits = 2)
format.default(c(6.0, 13.1), digits = 2, nsmall = 1)

## use of scientific
format(2^31-1)
format.default(2^31-1, sci = TRUE)

## a list
z <- list(a=letters[1:3], b=(-pi+0i)^((-2:2)/2), c=c(1,10,100,1000),
          d=c("a", "longer", "character", "string"))
format.default(z, digits = 2)
format.default(z, digits = 2, justify = "left", trim = FALSE)


[Package tutoR version 0.3.2 Index]