str_remove_decimals: Remove decimals from large numbers in string

View source: R/strings.R

str_remove_decimalsR Documentation

Remove decimals from large numbers in string

Description

str_remove_decimals is a function that for a character vector where each element is a single word or number identifies all decimal numbers (detected by a period .) and if the preceeding number of digits is larger than one, i.e., the number in the text is >=10, then the decimals are removed from the number. The intended use is to clean output to latex tables such that decimals for large numbers are removed. It is important that the numbers are stored in a single element in the string vector.

Usage

str_remove_decimals(string, pattern = NULL, n_digits = 2)

Arguments

string

Character string

pattern

Number pattern to look for

n_digits

Indicating how large the number must be before removing decimals. n_digits = 2 will remove decimals for numbers greater than or equal to 10, n_digits = 3 for numbers greater than or equal to 100 etc.

Details

Used in scripts: Robust function: TRUE

Value

Character string with decimals removed for large numbers

Examples


## Not run: 
str_remove_decimals("Hello, world 1,000.000")
str_remove_decimals("1.000")
str_remove_decimals("10.000")
str_remove_decimals("1,000.00")
str_remove_decimals(c("Hello, world", "1,000.00"))

## End(Not run)

AndreSjuve/dretools documentation built on Dec. 4, 2024, 3:12 a.m.