Below is an example of what I'm experiencing
library(tidyverse)
library(janitor)
x <- data_frame(c1=c('a','a','b','b'),
c2=c('a','b','c','d'),
c3=runif(4,0,10),
c4=runif(4,10,20),
c5=runif(4,20,100))
x %>%
adorn_totals(c('col')) %>%
adorn_percentages('row') %>%
adorn_pct_formatting() %>%
adorn_ns('front')
Running this code provides the following output:
c1 c2 c3 c4 c5 Total
a a (a) 1.0495149 (1.2%) 12.78693 (15.0%) 71.48728 (83.8%) 85.32373 (100.0%)
a b (b) 0.9217471 (0.9%) 19.71064 (20.1%) 77.67327 (79.0%) 98.30566 (100.0%)
b c (c) 9.0695540 (19.4%) 14.39917 (30.8%) 23.32479 (49.8%) 46.79351 (100.0%)
b d (d) 8.9398517 (7.8%) 18.53542 (16.1%) 87.43437 (76.1%) 114.90965 (100.0%)
As you can see, column c2 is just another character column and thus shouldn't be impacted by the adorn_ functions, but as I go from adorn_pct_formatting to adorn_ns it mutates that column in an unexpected way.
Does anyone know how to prevent this while maintaining my same general approach below; meaning that I continue to use the adorn_ functions from janitor?
I'm aware and capable of writing code to calculate and paste the N's and %s into each specific column manually but I'm looking specifically for a way to do it using the functions provided here, if possible.
Thank you.
I was unable to find a mechanism to prevent Janitor adorning the character columns.
There is also a bug logged on the Janitor repo where the adornment of character columns is discussed.
My solution was to process the character column after the adorn function byt splitting the string using stringr::strsplit.
I hope this is useful to others who come across this issue.