Coerce a surveytable table to a data frame
Source:R/as.data.frame.R
as.data.frame.surveytable_table.Rd
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
.
Usage
# S3 method for class 'surveytable_table'
as.data.frame(x, ...)
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