op_formula: Perform a mathematical operation on two formula

Description Usage Arguments Details Value Examples

View source: R/formula_math.R

Description

Perform a mathematical operation on two formula

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
op_formula(op, e1, e2)

multiply_formula(e1, e2)

divide_formula(e1, e2)

add_formula(e1, e2)

subtract_formula(e1, e2)

## S3 method for class 'formula'
Ops(e1, e2)

## S3 method for class 'formula'
Math(x, ...)

Arguments

op

The operation to perform either as a name or something that can be coerced into a name.

e1, e2, x

The formulae to operate on

...

Ignored.

Details

The method for combination depends if the two formula are one- or two-sided.

If both formula are one-sided, the right hand side (RHS) of both are added together with additional parentheses added, if parentheses appear to be needed. If both formula are two-sided, the left hand side (LHS) and RHS are separately added. If one formula is one-sided and the other is two-sided, the LHS is selected from the two-sided formula and the RHS follows rules as though two one-sided formula were added.

multiply_formula Multiply two formula (identical to (a~b) * (c~d)

divide_formula Divide two formula (identical to (a~b) / (c~d)

add_formula Add two formula (identical to (a~b) + (c~d)

subtract_formula Multiply two formula (identical to (a~b) - (c~d)

Ops.formula Supports generic binary operators and a couple of unary operators (see ?Ops).

Math.formula Supports generic unary operators (see ?Math).

Value

e1 and e2 combined by the operation with the environment from e1. See Details.

Examples

1
2
3
4
5
6
7
8
9
op_formula("+", a~b, c~d)
op_formula("+", a~b, ~d)
op_formula("+", ~b, c~d)
op_formula("+", ~b, ~d)
op_formula("-", a~b)
op_formula("-", -a~b) # Dumb, but accurate
op_formula("-", -a~b, c~-d) # Dumb, but accurate

log(a~b)

Example output

a + c ~ b + d
a ~ b + d
c ~ b + d
~b + d
-a ~ -b
-(-a) ~ -b
(-a) - c ~ b - (-d)
log(a) ~ log(b)

formulops documentation built on Feb. 22, 2020, 5:07 p.m.