View source: R/rmd.util.r View source: R/funs.unfinished.r
num2formattedStr | R Documentation |
Format a vector of numbers based on their distribution, removing non-informative digits.
isVecNumeric(v)
num2formattedStr(v,intTypeCutoff)
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. |
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
(boolean) by isVecNumeric
(character vector) formatted numbers in character by num2formattedStr
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.