Description Usage Arguments Details Value See Also Examples
Caculate the next element of a sequence from previous element(s) and a rule.
1 |
x |
- an object of class |
y |
- first element of numeric sequence |
z |
- second element of numeric sequence |
argument z
is ignored if x
inherits from class SingleRule
function returs single value of class numeric
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #[1] for objects of class SingleRule
# a rule adding a constant value '6' to the element of numeric sequence
p<-new("AddConstSingleRule", constantVal=6)
calculate(p,4)# 4+6=10
#[2] for combined objects
m<-new("DigSumSingleRule")
r<-new("AddConstSingleRule", constantVal=6)
g<-new("MultDoubleRule", firstRule=m, secondRule=m, nextSingle=r)
calculate(g,12,34) #27
# rule 'm' (first rule) is executed on the first element of numeric sequence (1+2=3)
# rule 'm' (second rule) is executed on the second element of numeric sequence (3+4=7)
# rule 'g' is executed on the result of firstRule and secondRule (3*7=21)
# rule 'r' (nextSingle) is executed on the result of DoubleRule (21+6=27)
#[(1+2) * (3+4)] + 6 = 27
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.