Learn R Programming

editrules (version 2.2-0)

substValue: Replace a variable by a value in a set of edits.

Description

Replace a variable by a value in a set of edits.

Given a set of linear restrictions $E: {\bf Ax}\odot {\bf b}$ with $\odot\in{<,\leq,==}$, and="" matrix="" ${\bf="" a}$="" with="" columns="" a}_1,{\bf="" a}_2,\ldots,{\bf="" a}_n$.="" substituting="" variable="" $x_j$="" a="" value="" $\tilde{\bf="" x}_j$="" means="" setting="" a}_j="0$" b}="{\bf" a}_j\tilde{x}_j$.<="" p="">

For editarrays, only rows with :==TRUE are kept. In the kept rows, categories not equal to are set to FALSE If reduce=TRUE, columns corresponding to categories which are set to FALSE will be removed. Note that the function reduce has a different effect (it removes complete variables).

For an editset, purely numerical variables are substitutes as in an editmatrix and categorical as in an editarray. Numerical variables appearing logical constraints are substituted and if truth values can be derived these are substituted in the logical constraint.

Usage

substValue(E, var, value, ...)

## S3 method for class 'editmatrix': substValue(E, var, value, reduce = FALSE, removeredundant = TRUE, ...)

## S3 method for class 'editarray': substValue(E, var, value, reduce = FALSE, ...)

## S3 method for class 'editset': substValue(E, var, value, simplify = TRUE, ...)

Arguments

Value

E, with variables replaced by values

Details

Note that the resulting editmatrix may be inconsistent because of inconsistencies in $\tilde{\bf x}$.

See Also

eliminate

Examples

Run this code
E <- editmatrix(expression(
    x + y == z,
    2*y < 10,
    3*x + 1.5*u < 7,
    z >= 0
    )
)

# single value
substValue(E,'z',10)
# multiple values
substValue(E,c('x','y'),c(1,3))
# remove substituted variable from edits
substValue(E,'z',10,reduce=TRUE)
# do not remove redundant row:
substValue(E,'z',10,removeredundant=FALSE)


# example with an editset
E <- editset(expression(
    x  + y == z,
    x >= 0,
    y >= 0,
    A %in% c('a1','a2'),
    B %in% c('b1','b2'),
    if ( x > 0 ) y > 0,
    if ( y > 0 ) x > 0,
    if ( A == 'a' ) B == 'b',
    if ( A == 'b' ) y > 3
    )
)

# substitute pure numerical variable
substValue(E,'z',10)
# substitute pure categorical variable
substValue(E,'A','a1')
# substitute variable appearing in logical constraints
substValue(E,'x',3)

Run the code above in your browser using DataLab