Home > Software engineering >  Scientific notation problems with grouped intervals
Scientific notation problems with grouped intervals

Time:06-14

I'm trying to group intervals of prices in $100,000 groups from a sample housing sale data set. I can't figure out how to eliminate the scientific notation on the groupings, and I've already tried options(scipen = 999) with no success.

Packages I have loaded are:

  1. tidyverse
  2. santoku
  3. janitor

Is there something in the santoku package or elsewhere that can make the intervals display, at least, as full numbers. Even better...display formatted as US currency?

Here's the code I'm using:

NH_12mo %>%  
  mutate(price_groups = chop(priceSold, seq(0, 2100000, by = 100000),
                             labels = lbl_dash("-"))) %>% 
  group_by(price_groups) %>% 
  summarize(n = n()) %>% 
  adorn_totals("row")

Here's the console output resulting from the above code:

price_groups   n
     1e 05-2e 05   6
     2e 05-3e 05   8
     3e 05-4e 05  24
     4e 05-5e 05  44
     5e 05-6e 05  58
     6e 05-7e 05  40
     7e 05-8e 05  32
     8e 05-9e 05  30
     9e 05-1e 06  13
   1e 06-1.1e 06   8
 1.1e 06-1.2e 06   5
 1.2e 06-1.3e 06   4
 1.3e 06-1.4e 06   5
 1.4e 06-1.5e 06   2
 1.5e 06-1.6e 06   3
   1.9e 06-2e 06   1
   2e 06-2.1e 06   1
           Total 284

dput() output is below for a reproducible example:

structure(list(priceSold = c(100000, 104000, 124900, 180000, 
190000, 190000, 210000, 210000, 225000, 239000, 260000, 270000, 
270000, 272000, 300000, 305000, 320000, 322000, 325000, 325000, 
330000, 339000, 340000, 340000, 350000, 355000, 355000, 362250, 
365000, 375000, 375000, 375000, 377000, 380000, 393000, 396000, 
399900, 399900, 400000, 400000, 405000, 415000, 415000, 420000, 
420000, 420000, 423000, 425000, 425000, 425000, 425000, 426000, 
429000, 430000, 430000, 435000, 439000, 439000, 440000, 440000, 
440000, 440000, 445000, 449900, 450000, 450000, 450000, 460000, 
460000, 462500, 470000, 477500, 480000, 480000, 480000, 484450, 
485000, 485000, 485000, 486000, 497777, 499950, 500000, 500000, 
500000, 500000, 502000, 504750, 505000, 510000, 510000, 510000, 
510000, 510000, 510000, 515000, 519900, 520000, 525000, 525000, 
525000, 525000, 525000, 525000, 528000, 529300, 530000, 540000, 
544500, 545000, 548303, 550000, 550000, 550000, 550000, 550000, 
552000, 555000, 559000, 560000, 560000, 565000, 566500, 570000, 
574000, 575000, 575000, 575000, 575000, 575000, 579000, 580000, 
580000, 585000, 585000, 585000, 585000, 585000, 585000, 592000, 
600000, 600000, 604000, 605000, 615000, 616000, 625000, 625000, 
625000, 625000, 630000, 630000, 636000, 640000, 640000, 640000, 
644000, 649250, 650000, 650000, 650000, 654600, 655000, 660000, 
660000, 660000, 665000, 665000, 670000, 675000, 675000, 675000, 
675000, 679000, 679900, 680000, 682000, 687500, 690000, 695000, 
700000, 700000, 702000, 712500, 720000, 720000, 725000, 735000, 
740000, 750000, 750000, 750000, 750000, 750000, 754565, 755000, 
755000, 765000, 770000, 775000, 775000, 775000, 775000, 780000, 
780000, 790000, 790000, 790000, 793000, 799500, 799900, 799900, 
800000, 800000, 800000, 801000, 810500, 820000, 825000, 825000, 
825000, 830000, 833000, 835000, 835000, 835000, 850000, 850000, 
850000, 850000, 850000, 865000, 865000, 874500, 875000, 875000, 
880000, 884500, 885000, 885000, 890000, 898000, 900000, 900000, 
913500, 925000, 949000, 950000, 955000, 980000, 990000, 995000, 
999000, 999000, 999999, 1000000, 1000000, 1000000, 1020000, 1023000, 
1030000, 1051000, 1075000, 1100000, 1100000, 1100000, 1125000, 
1180000, 1200000, 1200000, 1210000, 1290000, 1300000, 1300000, 
1315000, 1325000, 1350000, 1425000, 1450000, 1500000, 1533400, 
1560000, 1993500, 2050000)), row.names = c(NA, -284L), class = c("tbl_df", 
"tbl", "data.frame"))

CodePudding user response:

You could add fmt to the lbl_dash bit:

NH_12mo %>%  
  mutate(price_groups = chop(priceSold, seq(0, 2100000, by = 100000),
                             labels = lbl_dash("-", fmt = scales::dollar))) %>% 
  count(price_groups) %>%
  janitor::adorn_totals("row")

          price_groups   n
     $100,000-$200,000   6
     $200,000-$300,000   8
     $300,000-$400,000  24
     $400,000-$500,000  44
     $500,000-$600,000  58
     $600,000-$700,000  40
     $700,000-$800,000  32
     $800,000-$900,000  30
   $900,000-$1,000,000  13
 $1,000,000-$1,100,000   8
 $1,100,000-$1,200,000   5
 $1,200,000-$1,300,000   4
 $1,300,000-$1,400,000   5
 $1,400,000-$1,500,000   2
 $1,500,000-$1,600,000   3
 $1,900,000-$2,000,000   1
 $2,000,000-$2,100,000   1
                 Total 284
  • Related