num2formattedStr: Format a vector of numbers based on their distribution

View source: R/rmd.util.r View source: R/funs.unfinished.r

num2formattedStrR Documentation

Format a vector of numbers based on their distribution

Description

Format a vector of numbers based on their distribution, removing non-informative digits.

Usage

isVecNumeric(v)
num2formattedStr(v,intTypeCutoff)

Arguments

v

(vector) a numeric or char vector

intTypeCutoff

(integer, 10) if a number is an integer and its absolute value is less than intTypeCutoff, don't format. Set NULL to disable.

Details

isVecNumeric determines whether a vector, numeric or not, contains numbers only. This function is used because often numeric columns are accidently formatted as character or factor classes. If TRUE from isVecNumeric, num2formattedStr makes decision on the following four aspects of formatting based on the min, median, max values of the vector, so that the formatted numbers carry enough information and are in a length less than 10 characters.

  • number of significant digits

  • number of decimal points

  • whether to apply 1000 separator ','

  • whether to apply scientific notation

Value

(boolean) by isVecNumeric

(character vector) formatted numbers in character by num2formattedStr

Examples

library(wfr)
v1=c(-1032.789, 389.4789, 78.00)
num2formattedStr(v1)
v1=c(3.00, 8.00, -10.000)
num2formattedStr(v1)
v1=c(-0.1289, 0.0489, 0.0003765)
num2formattedStr(v1)
v1=c(-0.1289, 0.0489, 0.03765, NA, Inf, -Inf, NaN)
num2formattedStr(v1)
v1=c(-0.1289, 0.0489, 0.03765, NA,'', Inf, -Inf, NaN)
class(v1)
num2formattedStr(v1)

blueskypie/wfr documentation built on Feb. 6, 2024, 4:38 p.m.