str_remove_decimals_all: Remove decimals from large numbers in multiple long strings

View source: R/strings.R

str_remove_decimals_allR Documentation

Remove decimals from large numbers in multiple long strings

Description

str_remove_decimals_all is a function that for a character vector where each element is a string with multiple words or numbers 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. The input here is typically the output from stargazer.

Usage

str_remove_decimals_all(string, pattern = NULL, split_pattern = NULL, n_digits)

Arguments

string

Character vector

pattern

Number pattern to look for

split_pattern

Pattern to split each element of string vector by. This argument should ensure that each number stored in each string element is isolated by itself. In latex output, this is achieved by &

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: FALSE

Value

Character vector with strings where decimals are removed for large numbers

Examples

## Not run: 
str_remove_decimals_all(c("Hello & 1,000.000", "My text"))
str_remove_decimals_all("Hello; 10.000", "1.000 is low")

## End(Not run)

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