Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option for controlling the zero, NA characters #151

Open
richierocks opened this issue Mar 6, 2019 · 1 comment
Open

Add an option for controlling the zero, NA characters #151

richierocks opened this issue Mar 6, 2019 · 1 comment
Labels
help wanted ❤️ we'd love your help!

Comments

@richierocks
Copy link

If you have data with many zeroes, it can be useful to replace the 0 character with something subtler in printed output. For example, the Matrix package defaults to printing zeroes as a . for sparse matrices. Similarly, prettyNum() lets you override the zero character.

set.seed(1979)
# Sparse matrices print with . instead of 0 
library(Matrix)
spMatrix(10, 10, sample(10, 3), sample(10, 3), 1:3)
#> 10 x 10 sparse Matrix of class "dgTMatrix"
#>                          
#>  [1,] . . . . . . . . . .
#>  [2,] . . . . . . . . . .
#>  [3,] . . 3 . . . . . . .
#>  [4,] . . . . . . . . . .
#>  [5,] . 2 . . . . . . . .
#>  [6,] . . . . . . . . . .
#>  [7,] . . . . . . . . . .
#>  [8,] . . . . . . . . . .
#>  [9,] . . . . . . . . . .
#> [10,] . . . . . . . 1 . .

# You can specify this for vectors using prettyNum()
(pois <- rpois(100, 0.1))
#>   [1] 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0
#>  [36] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
#>  [71] 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
prettyNum(pois, zero.print = ".")
#>   [1] "." "." "." "." "." "." "1" "." "." "." "." "." "." "." "1" "." "."
#>  [18] "1" "." "." "." "." "." "1" "." "." "." "1" "." "." "1" "." "." "."
#>  [35] "." "." "." "." "." "." "." "." "." "." "." "." "." "." "." "." "."
#>  [52] "." "." "." "." "." "." "." "." "1" "." "." "." "." "." "." "." "."
#>  [69] "." "." "." "." "." "." "." "." "1" "." "." "." "." "." "." "." "."
#>  [86] "." "." "." "." "." "." "." "." "." "." "." "." "." "." "."

It seems useful to have a pillar option to allow overriding the zero character. Similarly, if data has a lot of missing values, it seems useful to have an option to replace NA with another subtler character.

@krlmlr
Copy link
Member

krlmlr commented Jun 30, 2022

Thanks. I wonder if this could be an option in num()?

@krlmlr krlmlr added help wanted ❤️ we'd love your help! and removed help wanted labels Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted ❤️ we'd love your help!
Projects
None yet
Development

No branches or pull requests

2 participants