| editarray | R Documentation |
An editarray is a boolean array (with some extra attributes)
where each row contains an edit restriction on purely categorical data.
The function editarray converts (a vector of) edit(s)
in character or expression from to an editarray object.
Edits may also be read from a data.frame, in which case it must have at least
a character column with the name edit. It is not
strictly necessary, but hightly recommended that the datamodel (i.e. the possible levels
for a variable) is included explicitly in the edits using an %in% statement, as shown
in the examples below. The function editfile can read categorical edits from a
free-form text file.
editarray(editrules, sep = ":", env = parent.frame())
## S3 method for class 'editarray'
as.character(x, useIf = TRUE, datamodel = TRUE, ...)
## S3 method for class 'editarray'
as.data.frame(x, ...)
## S3 method for class 'editarray'
as.expression(x, ...)
## S3 method for class 'editarray'
as.matrix(x, ...)
## S3 method for class 'editarray'
c(...)
## S3 method for class 'editarray'
summary(object, useBlocks = TRUE, ...)
editrules |
|
sep |
textual separator, to be used internally for separating variable from category names. |
env |
environment to evaluate the rhs of '==' or '%in%' in. |
x |
editarray object |
useIf |
|
datamodel |
|
... |
further arguments passed to or from other methods |
object |
an R object |
useBlocks |
|
editarray : An object of class editarray
as.data.frame: data.frame with columns 'name', 'edit' and 'description'.
as.matrix: The boolean matrix part of the editarray.
editrules.plotting, violatedEdits, localizeErrors,
editfile, editset, editmatrix, getVars,
blocks, eliminate, substValue, isFeasible
generateEdits, contains, is.editarray, isSubset
# Here is the prototypical categorical edit: men cannot be pregnant.
E <- editarray(expression(
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 (and using a character vector as input):
editarray(expression(
gender %in% c('male','female'),
pregnant %in% c(TRUE, FALSE),
if( gender == 'male' ) !pregnant
)
)
# the \%in\% statement may be used at will
editarray(expression(
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')
)
)
# Here is the prototypical categorical edit: men cannot be pregnant.
E <- editarray(expression(
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 (and using a character vector as input):
editarray(expression(
gender %in% c('male','female'),
pregnant %in% c(TRUE, FALSE),
if( gender == 'male' ) !pregnant
)
)
# the \%in\% statement may be used at will
editarray(expression(
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')
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.