update.survey.design: Add variables to a survey design

Description Usage Arguments Details Value See Also Examples

View source: R/survey.R

Description

Update the data variables in a survey design, either with a formula for a new set of variables or with an expression for variables to be added.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## S3 method for class 'survey.design'
update(object, ...)
## S3 method for class 'twophase'
update(object, ...)
## S3 method for class 'svyrep.design'
update(object, ...)
## S3 method for class 'DBIsvydesign'
update(object, ...)
## S3 method for class 'ODBCsvydesign'
update(object, ...)

Arguments

object

a survey design object

...

Arguments tag=expr add a new variable tag computed by evaluating expr in the survey data.

Details

Database-backed objects may not have write access to the database and so update does not attempt to modify the database. The expressions are stored and are evaluated when the data is loaded.

If a set of new variables will be used extensively it may be more efficient to modify the database, either with SQL queries from the R interface or separately. One useful intermediate approach is to create a table with the new variables and a view that joins this table to the table of existing variables.

There is now a base-R function transform for adding new variables to a data frame, so I have added transform as a synonym for update for survey objects.

Value

A survey design object

See Also

svydesign, svrepdesign, twophase

Examples

1
2
3
4
5
data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat,
fpc=~fpc)
dstrat<-update(dstrat, apidiff=api00-api99)
svymean(~api99+api00+apidiff, dstrat)

survey documentation built on March 18, 2018, 1:15 p.m.