Describe structure of Data Sets and Importers

Description

The function codeplan() creates a data frame that describes the structure of an item list (a data.set object or an importer object), so that this structure can be stored and and recovered. The resulting data frame has a particular print method that delimits the output to one line per variable.

With setCodeplan an item list structure (as returned by codeplan()) can be applied to a data frame or data set. It is also possible to use an assignment like codeplan(x) <- value to a similar effect.

Usage

codeplan(x)
## S4 method for signature 'item.list'
codeplan(x)
setCodeplan(x,value)
## S4 method for signature 'data.frame,codeplan'
setCodeplan(x,value)
## S4 method for signature 'data.set,codeplan'
setCodeplan(x,value)
codeplan(x) <- value

Arguments

x

for codeplan(x) an object that inherits from class "item.list", i.e. can be a "data.set" object or an "importer" object; for codeplan(x) <- value or setCodeplan(x,value) a data frame.

value

an object as it would be returned by codeplan(x)

Value

codeplan returns a data frame with additional S3 class attribute "codeplan". Such a data frame has the following variables:

name

The name of the item/variable in the item list or data set.

description

The description/variable label string of the item/variable.

annotation

code to recreate the annotation attribute,

labels

code to recreate the value labels,

value.filter

code to recreate the value filter attribute (declaration of missing values, range of valid values, or an enumeration of valid values.)

mode

a character string that describes storage mode, such as "character", "integer", or "numeric".

measurement

a character string with the measurement level, "nominal", "ordinal", "interval", or "ratio".

Examples

Data1 <- data.set(
         vote = sample(c(1,2,3,8,9,97,99),size=300,replace=TRUE),
         region = sample(c(rep(1,3),rep(2,2),3,99),size=300,replace=TRUE),
         income = exp(rnorm(300,sd=.7))*2000
         )
Data1 <- within(Data1,{
 description(vote) <- "Vote intention"
 description(region) <- "Region of residence"
 description(income) <- "Household income"
 foreach(x=c(vote,region),{
   measurement(x) <- "nominal"
   })
 measurement(income) <- "ratio"
 labels(vote) <- c(
                   Conservatives         =  1,
                   Labour                =  2,
                   "Liberal Democrats"   =  3,
                   "Don't know"          =  8,
                   "Answer refused"      =  9,
                   "Not applicable"      = 97,
                   "Not asked in survey" = 99)
 labels(region) <- c(
                   England               =  1,
                   Scotland              =  2,
                   Wales                 =  3,
                   "Not applicable"      = 97,
                   "Not asked in survey" = 99)
 foreach(x=c(vote,region,income),{
   annotation(x)["Remark"] <- "This is not a real survey item, of course ..."
   })
 missing.values(vote) <- c(8,9,97,99)
 missing.values(region) <- c(97,99)
)
cpData1 <- codeplan(Data1)
Data2 <- data.frame(
         vote = sample(c(1,2,3,8,9,97,99),size=300,replace=TRUE),
         region = sample(c(rep(1,3),rep(2,2),3,99),size=300,replace=TRUE),
         income = exp(rnorm(300,sd=.7))*2000
         )
codeplan(Data2) <- cpData1
codebook(Data2)
================================================================================

   vote 'Vote intention'

--------------------------------------------------------------------------------

   Storage mode: double
   Measurement: nominal
   Missing values: 8, 9, 97, 99

            Values and labels    N    Percent

    1   'Conservatives'         44   38.3 14.7
    2   'Labour'                34   29.6 11.3
    3   'Liberal Democrats'     37   32.2 12.3
    8 M 'Don't know'            51        17.0
    9 M 'Answer refused'        47        15.7
   97 M 'Not applicable'        39        13.0
   99 M 'Not asked in survey'   48        16.0

   Remark:
       This is not a real survey item, of course ...

================================================================================

   region 'Region of residence'

--------------------------------------------------------------------------------

   Storage mode: double
   Measurement: nominal
   Missing values: 97, 99

            Values and labels    N    Percent

    1   'England'              121   45.7 40.3
    2   'Scotland'              97   36.6 32.3
    3   'Wales'                 47   17.7 15.7
   97 M 'Not applicable'         0         0.0
   99 M 'Not asked in survey'   35        11.7

   Remark:
       This is not a real survey item, of course ...

================================================================================

   income 'Household income'

--------------------------------------------------------------------------------

   Storage mode: double
   Measurement: ratio

            Min:    256.511
            Max:  12428.023
           Mean:   2553.043
       Std.Dev.:   2011.723
       Skewness:      2.211
       Kurtosis:      6.138

   Remark:
       This is not a real survey item, of course ...