https://github.com/indenkun/numcomma
`{NumComma}` can convert between comma-separated and non-comma-separated numbers every three digits on R.
https://github.com/indenkun/numcomma
comma-separated comma-separated-values convert r
Last synced: 2 months ago
JSON representation
`{NumComma}` can convert between comma-separated and non-comma-separated numbers every three digits on R.
- Host: GitHub
- URL: https://github.com/indenkun/numcomma
- Owner: indenkun
- License: other
- Created: 2020-12-01T14:01:58.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-13T13:57:14.000Z (over 4 years ago)
- Last Synced: 2025-01-27T08:11:45.232Z (4 months ago)
- Topics: comma-separated, comma-separated-values, convert, r
- Language: R
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```[English](README.md) | [日本語](README_JP.md)
# NumComma
`{NumComma}` can convert between comma-separated and non-comma-separated numbers every three digits on R.
It also has the `*_str` function for handling comma-separated and non-comma-separated numbers in a string.
## Installation
You can install it in
``` r
remotes::install_github("indenkun/NumComma")
```## Example
```{r example}
library(NumComma)
````{NumComma}` has two functions: `NumComma_rm` for converting comma-separated numbers into uncomma-separated numbers every three digits, and `NumComma_add` for converting numbers into comma-separated numbers (strings) every three digits. And there are extensions to these functions, `NumComma_rm_str` and `NumComma_add_str`, which perform the conversion for each digit in a string.
### `NumComma_rm` and `NumComma_rm_str`
`NumComma_rm` can convert comma-separated numbers (strings) into numbers without commas every three digits.
```{r}
NumComma_rm("2,020")
```If the number does not contain a comma, it returns the same number.
```{r}
NumComma_rm("2020")
```Numbers containing numbers after the decimal point can also be converted.
```{r}
NumComma_rm("1,234.56")
```Numbers containing numbers after the decimal point can also be converted.
```{r}
x <- c("2,020", "2020", "1,234.56")
NumComma_rm(x)
```It is also possible to return the value as a number instead of a string by using `convert` with `TRUE`.
```{r}
x <- c("2,020", "2020", "1,234.56")
NumComma_rm(x, convert = TRUE)
```If you enter a number with a comma or a non-comma value for every three digits, it returns the value as it was entered with a warning message.
```{r}
NumComma_rm("1,23,456")
NumComma_rm("NumComma_rm")
```The warning text can be disabled by specifying `FALSE` in `Warnig.message`.
```{r}
NumComma_rm(c("1,23,456", "NumComma_rm"), warnig.message = FALSE)
````NumComma_rm_str` is a function for converting a comma-separated number to an uncomma-separated number for every three digits in a string.
```{r}
NumComma_rm_str("The total population of Japan is 124,271,318 as of January 1, 2020.")
```### `NumComma_add` and `NumComma_add_str`
NumComma_add` is a function for converting numbers into comma-separated numbers (strings) of three digits.
It can accept a number or a string that represents a number.
```{r}
NumComma_add(123456)
NumComma_add("123456")
```If you enter consecutive numbers starting from 0 as a string it will return the value as is.
```{r}
NumComma_add("0001")
```If you enter a string that is not a number string (including numbers containing commas), it returns the value you entered with a warning message.
```{r}
NumComma_add(c("NumComma_add", "1,234"))
```The warning text can be disabled by specifying `FALSE` in `Warnig.message`.
```{r}
NumComma_add(c("NumComma_add", "1,234"), warnig.message = FALSE)
```You can also use `digit` to convert only numbers with more than the number of digits (including decimal places) specified by `digit` into comma-separated numbers with every three digits, or `small.num` to convert only numbers with more than the number of digits specified by `small.num` into comma-separated numbers with every three digits.
```{r}
NumComma_add(c(123456, 2020), digit = 4)
NumComma_add(c(123456, 2020), small.num = 3000)
````NumComma_add_str` is a function for converting numbers in a string to comma-separated numbers.
```{r}
NumComma_add_str("The total population of Japan is 124271318 people as of January 1, 2020.")
```The `NumComma_add_str`, like the `NumComma_add`, can control the number to be converted by arguments.
```{r}
NumComma_add_str("The total population of Japan is 124271318 people as of January 1, 2020.", digit = 4)
NumComma_add_str("The total population of Japan is 124271318 people as of January 1, 2020.", small.num = 3000)
```## License
MIT.
## Imports
* `{purrr}`
* `{stringr}`
* `{stats}`
* `{dplyr}`