Learn R Programming

surveycore (version 0.8.3)

from_svydesign: Convert a survey Package Design to a surveycore Design Object

Description

Converts a survey package design object (svydesign, svrepdesign, or twophase) to the corresponding surveycore S7 object. The data, design variables, and replicate weights are preserved; metadata (variable labels, value labels) is not — the survey package has no metadata system.

Usage

from_svydesign(x)

Value

A survey_taylor, survey_replicate, or survey_twophase object.

Arguments

x

A survey::svydesign, survey::svrepdesign, survey::twophase, or srvyr::tbl_svy object.

Details

Weight column names are recovered from the design call when available. When the call does not contain a formula (e.g., weights were passed as a vector), the weight column is identified by matching the stored weight values against columns in the data. If no match is found, a ..surveycore_wt.. column is added.

See Also

as_svydesign() to convert in the other direction

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

Examples

Run this code
if (requireNamespace("survey", quietly = TRUE)) {
  sv <- survey::svydesign(
    ids = ~sdmvpsu, weights = ~wtint2yr, strata = ~sdmvstra,
    data = nhanes_2017, nest = TRUE
  )
  d <- from_svydesign(sv)
  survey_data(d)
}

Run the code above in your browser using DataLab