Skip to contents

If a tabulation function produces multiple tables, that group of tables is a list, with each element of the list being an individual table. To convert one of these tables to a data.frame, use [[. For example, in the following code, we generate 3 tables, and then convert the third table to a data.frame.

set_survey(namcs2019sv)
mytables = tab("MDDO", "SPECCAT", "MSA")
mydf = as.data.frame(mytables[[3]])

Usage

# S3 method for class 'surveytable_table'
as.data.frame(x, ...)

Arguments

x

a table produced by a tabulation function

...

ignored

Value

A data frame.

Examples

set_survey(namcs2019sv)
#>                         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)                       │
#> └───────────┴──────────────┴────────────────────────────────────────────────┘
#> 
as.data.frame( tab("AGER") )
#>               Level    n    Number       SE        LL        UL Percent SE.1
#> 1    Under 15 years  887 117916772 14097315  93228928 149142177    11.4  1.3
#> 2       15-24 years  542  64855698  7018359  52386950  80292164     6.3  0.6
#> 3       25-44 years 1435 170270604 13965978 144924545 200049472    16.4  1.1
#> 4       45-64 years 2283 309505956 23289827 266994092 358786727    29.9  1.4
#> 5       65-74 years 1661 206865982 14365993 180480708 237108637    20.0  1.2
#> 6 75 years and over 1442 167069344 15179082 139746193 199734713    16.1  1.3
#>   LL.1 UL.1
#> 1  8.9 14.2
#> 2  5.1  7.5
#> 3 14.3 18.8
#> 4 27.2 32.6
#> 5 17.6 22.5
#> 6 13.7 18.8