formatdf: Format a Data Frame

Description Usage Arguments Details Value See Also Examples

View source: R/formatdf.R

Description

Format selected columns of a data frame for pretty viewing or printing.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
formatdf(
  df,
  numercol = NULL,
  round2 = 0,
  ndec = round2,
  comma = ",",
  characol = NULL,
  align = "left",
  keepnum = TRUE
)

Arguments

df

Data frame to be formatted.

numercol

Numeric vector, index of numeric columns to format, default, NULL, uses all numeric and integer columns.

round2

Integer vector, indicating what place numbers should be rounded to, default 0.

ndec

Integer vector, indicating how many places to the right of the decimal point should be displayed, default round2.

comma

Character vector, indicating thousands character separator, default ",".

characol

Numeric vector, index of character columns to format, default, NULL, uses all character and factor columns.

align

Character vector, indicating justification of character columns, default "left". Other options include "right", "centre", and "none".

keepnum

Logical scalar, indicating if numeric columns should be kept as numeric, default TRUE, or converted to character.

Details

If a vector of length 1 is provided for round2, ndec, comma, or align, the same rounding, decimals, commas, or alignment is applied to all specified columns.

Value

A data frame, the same dimensions as df with selected columns rounded and/or formatted and converted to character.

See Also

format.

Examples

1
2

JVAdams/jvamisc documentation built on Aug. 11, 2021, 6:43 a.m.