Skip to contents

Take damage values that include letters for order of magnitude (e.g., "2K" for $2,000) and return a numeric value of damage.

Usage

parse_damage(damage_vector)

Arguments

damage_vector

A character vector with damage values (e.g., the damage_crops or damage_property columns in the NOAA Storm Events data). This vector should give numbers except for specific abbreviations specifying order of magnitude (see Details).

Value

The input vector, parsed to a numeric, with abbreviations for orders of magnitude appropriately interpreted (e.g., "2K" in the input vector becomes the numeric 2000 in the output vector).

Details

This function parses the following abbreviations for order of magnitude:

  • "K": 1,000 (thousand)

  • "M": 1,000,000 (million)

  • "B": 1,000,000,000 (billion)

  • "T": 1,000,000,000,000 (trillion)

Examples

damage_crops <- c("150", "2K", "3.5B", NA)
parse_damage(damage_crops)
#> [1] 1.5e+02 2.0e+03 3.5e+09 0.0e+00