Skip to contents

Converts a surveycore design object to an srvyr tbl_svy by first converting to a survey design via as_svydesign() and then wrapping with srvyr::as_survey(). Requires both survey and srvyr.

Usage

as_tbl_svy(x)

Arguments

x

A survey_taylor, survey_replicate, survey_twophase, or survey_nonprob object.

Value

A srvyr::tbl_svy object. Value labels are not carried into the returned object — the survey package has no metadata system. To read the data back with haven-style classes rebuilt, use survey_data(x, haven_class = TRUE) on the surveycore design instead.

Details

Metadata (variable labels, value labels) is NOT carried over.

See also

from_tbl_svy() to convert back from a tbl_svy object

Other conversion: as_svydesign(), from_svydesign(), from_tbl_svy()

Examples

d <- as_survey(
  nhanes_2017,
  ids = sdmvpsu,
  weights = wtint2yr,
  strata = sdmvstra,
  nest = TRUE
)
if (
  requireNamespace("survey", quietly = TRUE) &&
    requireNamespace("srvyr", quietly = TRUE)
) {
  ts <- as_tbl_svy(d)
}