editmatrix {editrules} | R Documentation |
Create an editmatrix
Description
An editmatrix
is a numerical matrix and a set of comparison operators representing
a linear system of (in)equations.
Usage
editmatrix(editrules, normalize = TRUE)
## S3 method for class 'editmatrix'
as.data.frame(x, ...)
## S3 method for class 'editmatrix'
as.character(x, ...)
## S3 method for class 'editmatrix'
as.expression(x, ...)
## S3 method for class 'editmatrix'
as.matrix(x, ...)
## S3 method for class 'editmatrix'
c(...)
## S3 method for class 'editmatrix'
str(object, ...)
## S3 method for class 'editmatrix'
summary(object, useBlocks = TRUE, ...)
Arguments
editrules |
A |
normalize |
|
x |
editmatrix object |
... |
Arguments to pass to or from other methods |
object |
an R object |
useBlocks |
|
Details
The function editmatrix
generates an editmatrix from a character
vector, an expression
vector or a data.frame
with at least the column edit
. The function editfile
reads edits from a free-form textfile, function as.editmatrix
converts a matrix, a vector of
constants and a vector of operators to an editmatrix
By default, the editmatrix
is normalized, meaning that all comparison operators are converted
to one of <
, <=
, or ==
. Users may specify edits using any of the operators
<, <=, ==, >=, >
(see examples below). However it is highly recommended to let editmatrix
parse them into normal
form as all functions operating on editmatrices expect or convert it to normal form anyway.
Value
editmatrix
: An object of class editmatrix
as.data.frame
a 3-column data.frame
with columns 'name' and 'edit'.
If the input editmatrix has a description
attribute a third column is returned.
as.matrix
: Augmented matrix
of editmatrix
. (See also getAb
).
Note
since version 2.0-0, the behaviour of as.data.frame.editmatrix
changed to be more symmetrical
with editmatrix.data.frame
and as.data.frame.editarray
.
Use editrules:::toDataFrame
(unsupported) for the old behaviour.
See Also
editrules.plotting
, violatedEdits
, localizeErrors
,
normalize
, contains
, is.editmatrix
,
getA
, getAb
, getb
, getOps
getVars
,
eliminate
, substValue
, isFeasible
Examples
# Using a character vector to define contraints
E <- editmatrix(c("x+3*y==2*z", "x==z"))
print(E)
# Using a expression vector to define contraints
E <- editmatrix(expression(x+3*y==2*z, x==z))
print(E)
# an editmatrix also has a summary method:
summary(E)
# select rows from an editmatrix:
E <- editmatrix(c("x+3*y==2*z", "x >= z"))
E[getOps(E) == "=="]
#Using data.frame to define constraints
E.df <- data.frame(
name =c("A","B","C"),
edit = c("x == y",
"z + w == y + x",
"z == y + 2*w"),
description = c(
"these variables should be equal","","")
)
print(E.df)
E <- editmatrix(E.df)
print(E)
# Using a character vector to define contraints
E <- editmatrix(c("x+3*y==2*z", "x==z"))
print(E)
# Using a expression vector to define contraints
E <- editmatrix(expression(x+3*y==2*z, x==z))
print(E)
# an editmatrix also has a summary method:
summary(E)
# select rows from an editmatrix:
E <- editmatrix(c("x+3*y==2*z", "x >= z"))
E[getOps(E) == "=="]
#Using data.frame to define constraints
E.df <- data.frame(
name =c("A","B","C"),
edit = c("x == y",
"z + w == y + x",
"z == y + 2*w"),
description = c(
"these variables should be equal","","")
)
print(E.df)
E <- editmatrix(E.df)
print(E)