Learn R Programming

editrules (version 2.2-0)

editarray: Parse textual, categorical edit rules to an editarray

Description

Transforms a list of categorical edit rules to a boolean array representation. An editarry is used to store demands on purely categorical data.

Usage

editarray(editrules, sep = ":", env = parent.frame())

Arguments

Value

editarray

itemize

  • "if( ) "

code

c(gender:male=TRUE, gender:female=FALSE, pregnant:TRUE=TRUE, pregnant:FALSE=FALSE)

eqn

$m\times n$

Details

The purpose of this function is to turn human-readable demands on categorical data to a boolean array. Categorical edit rules state demands on a dataset in the form of a quoted R expression. Allowed statements include if, operators %in%, ==, !=, ||, && and brackets () and {}.

The datamodel is derived from the edit set. A data model can be defined by simply adding univariate edits of the form

  • " %in% c('','',...,'')"

See Also

editfile

Examples

Run this code
# Here is the prototypical categorical edit: men cannot be pregnant.
E <- editarray(c(
    "gender \%in\% c('male','female')",
    "pregnant \%in\% c('yes','no')",
    "if( gender == 'male' ) pregnant == 'no'"
    )
)
E

# an editarray has a summary method:
summary(E)

# A yes/no variable may also be modeled as a logical:
editarray(expression(
    gender \%in\% c('male','female'),
    pregnant \%in\% c(TRUE, FALSE),
    if( gender == 'male' ) pregnant == FALSE
    )
)

# or, shorter: 
editarray(c(
    "gender \%in\% c('male','female')",
    "pregnant \%in\% c(TRUE, FALSE)",
    "if( gender == 'male' ) !pregnant"
    )
)

# the \\\%in\\\% statement may be used at will
editarray(c(
    "gender \%in\% c('male','female')",
    "pregnant \%in\% c(TRUE, FALSE)",
    "positionInHousehold \%in\% c('marriage partner', 'child', 'other')",
    "maritalStatus \%in\% c('unmarried','married','widowed','divorced')",
    "if( gender == 'male' ) !pregnant",
    "if( maritalStatus \%in\% c('unmarried','widowed','divorced')) !positionInHousehold \%in\% c('marriage partner','child')"
    )
)

Run the code above in your browser using DataLab