knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )

wordstonumbers is an R package for text analysis pre-processing that transforms numbers written in words to numeric digits (e.g., “one hundred and twenty three thousand” to “123000”). Works on numbers up to the decillions.

You can install wordstonumbers from github with:

# install.packages("devtools") devtools::install_github("fsingletonthorn/words_to_numbers")

The words_to_numbers function deals with the most common ways that numbers are reported as words. For example:

library(wordstonumbers) words_to_numbers("ninety-nine red balloons") words_to_numbers("The answer is forty-two")

words_to_numbers("The PRQ is a twelve-item, four-point Likert scale (from one = Never to four = Very Often) with three sub-scores.") words_to_numbers("The Library of Babel (by Jorge Luis Borges) describes a library that contains all possible four-hundred and ten page books made with a character set of twenty five characters (twenty two letters, as well as spaces, periods, and commas), with eighty lines per book and forty characters per line.")

This function attempts to break numbers apart 'intelligently', guessing which values are likely to represent separate numbers, e.g.:

words_to_numbers("one two three four") words_to_numbers("one hundred and seventeen one hundred")

The function can also deal with some common cases where non-decimal numeric digits are interspersed with numbers-as-words.

words_to_numbers("three hundred billion, two hundred and 79 cats") words_to_numbers("300 billion, 2 hundred and 79 cats") words_to_numbers("17 hundred cats")

Magnitude values (e.g., million, billion, etc) preceded by decimals are processed correctly if the proceeding value is given in numeric digits.

words_to_numbers("1.6 Billion") words_to_numbers("1.23212 thousand")

However, not all ways that numbers can reported in text are correctly transformed at the moment.

At the moment, this function transforms numbers separated by "point" or "dot" into a single number:

words_to_numbers("One point six") words_to_numbers("six dot one")

However, it does not collapse *multiple* numbers after the decimal. The function currently reads the values after the decimal using the same rules as for normal numbers, meaning that if people list numbers after decimals they will be read as separate values.

words_to_numbers('three point one four one five nine two six') words_to_numbers("One point six billion")

It's also important to note that this package does not yet recognize that certain numbers are likely to represent years.

words_to_numbers('nineteen twenty')

**Please report any bugs or issues you see here!**

fsingletonthorn/words_to_numbers documentation built on Jan. 13, 2020, 5:05 a.m.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.