Suppose you have data that looks something like this
df <- data.frame(income = rnorm(1000,77345,30569))
You add a column to indicate the quartile interval factor that each observation falls under
df$quant <- cut(df$income, quantile(df$income))
The factor levels look something like this
Levels: (-4.48e+04,5.6e+04] (5.6e+04,7.69e+04] (7.69e+04,9.73e+04] (9.73e+04,1.64e+05]
How can you programmatically, not manually, change the intervals so they print out nicely in a frequency summary table?
df %>% count(quant)
Which prints like this:
quant n
1 (-4.48e+04,5.6e+04] 249
2 (5.6e+04,7.69e+04] 250
3 (7.69e+04,9.73e+04] 250
4 (9.73e+04,1.64e+05] 250
I want it to look something like this
quant n
1 ($44,800,$56,000] 249
2 ($56,000,$76,900] 250
3 ($76,900,$97,300] 250
4 ($97,300,$164,000] 250
This is just for printing purposes (in a Rmarkdown report). I have made all calculations and plotting without a problem already.