Learn R Programming

editrules (version 2.2-0)

violatedEdits: Retrieve which rows of data.frame dat violate which constraints

Description

This is an S3 generic function for checking rows of a data.frame against a number of edit restrictions. The edits can be entered either in character data.frame or editmatrix format. The returned value is a logical matrix with dimension (number of records )$times$(number of edits), indicating which record violates (TRUE) which edit.

  • For rules of the form Ax == b |Ax - b| <= tol="" is="" returned.<="" li="">
For rules of the form Ax < b, Ax - b < tol is returned. For rules of the form Ax <= b="" ax-="" <="tol" is="" returned.<="" item="">

Usage

violatedEdits(E, dat, ...)

## S3 method for class 'character': violatedEdits(E, dat, name = NULL, ...)

## S3 method for class 'editmatrix': violatedEdits(E, dat, tol = 0, ...)

## S3 method for class 'data.frame': violatedEdits(E, dat, ...)

## S3 method for class 'editarray': violatedEdits(E, dat, datamodel = TRUE, ...)

## S3 method for class 'editset': violatedEdits(E, dat, datamodel = TRUE, ...)

Arguments

Value

a logical matrix where each row indicates which contraints are violated

code

sqrt(.Machine$double.eps)

Details

This function can be used as an input for automatic corrections methods. This method will fail if E contains variables that are not available in dat

See Also

listViolatedEdits, checkRows

Examples

Run this code
# Using character vector to define contraints
E <- editmatrix(c( "x+3*y==2*z"
                  , "x==z"
                  )
                )
                
dat <- data.frame( x = c(0,2,1)
                 , y = c(0,0,1)
                 , z = c(0,1,1)
                 )
print(dat)

ve <- violatedEdits(E,dat)

print(ve)
summary(ve, E)
plot(ve)

# An example with categorical data:

E <- editarray(c(
    "gender \%in\% c('male','female')",
    "pregnant \%in\% c(TRUE, FALSE)",
    "if( gender == 'male' ) !pregnant"
    )
)
print(E)

dat <- data.frame(
    gender=c('male','male','female','cylon'), 
    pregnant=c(TRUE,FALSE,TRUE,TRUE)
)

print(dat)
# Standard, the datamodel is checked as well,
violatedEdits(E,dat)

# but we may turn this of
violatedEdits(E,dat,datamodel=FALSE)

Run the code above in your browser using DataLab