Skip to contents

Restructure the output of the tabulation functions to make it more structured and easier to process programmatically.

Usage

restructure(tab_output, lvls = c())

Arguments

tab_output

output from a tabulation function. An object of class surveytable_table or surveytable_list.

lvls

(optional) only show these levels.

Value

data.frame

See also

Examples

set_survey(namcs2019sv, mode = "nchs")
#> * Mode: NCHS.
#>                         Survey info {NAMCS 2019 PUF}                         
#> ┌───────────┬──────────────┬────────────────────────────────────────────────┐
#> │ Variables │ Observations │ Design                                         │
#> ├───────────┼──────────────┼────────────────────────────────────────────────┤
#> │        33 │        8,250 │ Stratified 1 - level Cluster Sampling design   │
#> │           │              │ (with replacement)                             │
#> │           │              │ With (398) clusters.                           │
#> │           │              │ namcs2019sv = survey::svydesign(ids = ~CPSUM,  │
#> │           │              │ strata = ~CSTRATM, weights = ~PATWT            │
#> │           │              │ , data = namcs2019sv_df)                       │
#> └───────────┴──────────────┴────────────────────────────────────────────────┘
#> 

## total() |> restructure()
restructure( total() )
#>      n Number..000. SE..000. LL..000. UL..000.            .attr_title
#> 1 8250      1036484    48836   945014  1136809 Total {NAMCS 2019 PUF}
#>                                                        .attr_footer .parens1
#> 1 N = 8250. Checked NCHS presentation standards. Nothing to report.       NA
#>   .parens2 .flag_R .flag_Cx .flag_Cdf .flag_Px .flag_Pc .flag_Pdf .flag_P0
#> 1       NA   FALSE    FALSE     FALSE    FALSE    FALSE     FALSE    FALSE

## tab_subset("MAJOR", "AGER") |> restructure(lvls = c("Pre-surgery", "Post-surgery"))
mytables = tab_subset("MAJOR", "AGER")
restructure(mytables, lvls = c("Pre-surgery", "Post-surgery"))
#>           Level   n Number..000. SE..000. LL..000. UL..000. Percent  SE  LL
#> 1   Pre-surgery  13          455      240      128     1615     0.4 0.2 0.1
#> 2  Post-surgery  44         1539      565      725     3270     1.3 0.5 0.5
#> 3   Pre-surgery   5          489      305       14    16552     0.8 0.5 0.1
#> 4  Post-surgery  45         3903     1317     1803     8448     6.0 1.7 3.1
#> 5   Pre-surgery  28         1864      596      951     3656     1.1 0.4 0.5
#> 6  Post-surgery 113        10460     1975     7107    15396     6.1 1.0 4.2
#> 7   Pre-surgery  46         3919     1362     1775     8655     1.3 0.4 0.5
#> 8  Post-surgery 204        17374     3203    11997    25163     5.6 1.1 3.7
#> 9   Pre-surgery  45         4328     1187     2412     7764     2.1 0.6 1.1
#> 10 Post-surgery 153        14301     2612     9872    20719     6.9 1.2 4.7
#> 11  Pre-surgery  22         1808      672      754     4336     1.1 0.4 0.4
#> 12 Post-surgery 100         6592     1655     3903    11132     3.9 1.0 2.2
#>      UL
#> 1   1.1
#> 2   2.7
#> 3   2.4
#> 4  10.5
#> 5   2.0
#> 6   8.6
#> 7   2.5
#> 8   8.1
#> 9   3.5
#> 10  9.8
#> 11  2.2
#> 12  6.4
#>                                                                              .attr_title
#> 1     Major reason for this visit (Patient age recode = Under 15 years) {NAMCS 2019 PUF}
#> 2     Major reason for this visit (Patient age recode = Under 15 years) {NAMCS 2019 PUF}
#> 3        Major reason for this visit (Patient age recode = 15-24 years) {NAMCS 2019 PUF}
#> 4        Major reason for this visit (Patient age recode = 15-24 years) {NAMCS 2019 PUF}
#> 5        Major reason for this visit (Patient age recode = 25-44 years) {NAMCS 2019 PUF}
#> 6        Major reason for this visit (Patient age recode = 25-44 years) {NAMCS 2019 PUF}
#> 7        Major reason for this visit (Patient age recode = 45-64 years) {NAMCS 2019 PUF}
#> 8        Major reason for this visit (Patient age recode = 45-64 years) {NAMCS 2019 PUF}
#> 9        Major reason for this visit (Patient age recode = 65-74 years) {NAMCS 2019 PUF}
#> 10       Major reason for this visit (Patient age recode = 65-74 years) {NAMCS 2019 PUF}
#> 11 Major reason for this visit (Patient age recode = 75 years and over) {NAMCS 2019 PUF}
#> 12 Major reason for this visit (Patient age recode = 75 years and over) {NAMCS 2019 PUF}
#>                                                                                          .attr_footer
#> 1  N = 887. Checked NCHS presentation standards: Cx: suppress count (and rate); Px: suppress percent.
#> 2  N = 887. Checked NCHS presentation standards: Cx: suppress count (and rate); Px: suppress percent.
#> 3                        N = 542. Checked NCHS presentation standards: Cx: suppress count (and rate).
#> 4                        N = 542. Checked NCHS presentation standards: Cx: suppress count (and rate).
#> 5                                   N = 1435. Checked NCHS presentation standards. Nothing to report.
#> 6                                   N = 1435. Checked NCHS presentation standards. Nothing to report.
#> 7                       N = 2283. Checked NCHS presentation standards: Cx: suppress count (and rate).
#> 8                       N = 2283. Checked NCHS presentation standards: Cx: suppress count (and rate).
#> 9                       N = 1661. Checked NCHS presentation standards: Cx: suppress count (and rate).
#> 10                      N = 1661. Checked NCHS presentation standards: Cx: suppress count (and rate).
#> 11                      N = 1442. Checked NCHS presentation standards: Cx: suppress count (and rate).
#> 12                      N = 1442. Checked NCHS presentation standards: Cx: suppress count (and rate).
#>              .parens1          .parens2 .flag_R .flag_Cx .flag_Cdf .flag_Px
#> 1  Patient age recode    Under 15 years   FALSE     TRUE     FALSE    FALSE
#> 2  Patient age recode    Under 15 years   FALSE     TRUE     FALSE    FALSE
#> 3  Patient age recode       15-24 years   FALSE     TRUE     FALSE    FALSE
#> 4  Patient age recode       15-24 years   FALSE     TRUE     FALSE    FALSE
#> 5  Patient age recode       25-44 years   FALSE    FALSE     FALSE    FALSE
#> 6  Patient age recode       25-44 years   FALSE    FALSE     FALSE    FALSE
#> 7  Patient age recode       45-64 years   FALSE     TRUE     FALSE    FALSE
#> 8  Patient age recode       45-64 years   FALSE    FALSE     FALSE    FALSE
#> 9  Patient age recode       65-74 years   FALSE    FALSE     FALSE    FALSE
#> 10 Patient age recode       65-74 years   FALSE    FALSE     FALSE    FALSE
#> 11 Patient age recode 75 years and over   FALSE     TRUE     FALSE    FALSE
#> 12 Patient age recode 75 years and over   FALSE    FALSE     FALSE    FALSE
#>    .flag_Pc .flag_Pdf .flag_P0
#> 1     FALSE     FALSE    FALSE
#> 2     FALSE     FALSE    FALSE
#> 3     FALSE     FALSE    FALSE
#> 4     FALSE     FALSE    FALSE
#> 5     FALSE     FALSE    FALSE
#> 6     FALSE     FALSE    FALSE
#> 7     FALSE     FALSE    FALSE
#> 8     FALSE     FALSE    FALSE
#> 9     FALSE     FALSE    FALSE
#> 10    FALSE     FALSE    FALSE
#> 11    FALSE     FALSE    FALSE
#> 12    FALSE     FALSE    FALSE