find_factors {lazy.symbolic} | R Documentation |
Decompose a Term into Multiplicative Factors separated by *, / or %*%.
find_factors(exp, markso = 1, sort = 0, debug = 0)
exp |
An expression vector or matrix |
markso |
= 0 not to mark the special opeartors |
sort |
= 1 to sort the factors according to their names |
debug |
= 1 to print the intermediate result |
It is assumed that there is just one character in between % and %.
The i-th factor with the preceding operator of exp is
substr( exp0, fromto[i,1], fromto[i,2] ) where
exp0 is the blank compressed exp.
The prefix operator associated with the i-th factor is oper[i].
The original expression can be recovered as:
res <- find_factors( exp ) expr <- paste( mapply( paste, res$oper, res$factor, sep="" ), collapse="" )
or
expr <- paste( paste( res$oper, res$factor, sep="" ), collapse="" )
The unbalanced parens, if any, will be neglected.
The factors can be sorted according to their names as follows:
res <- find_factors("A*d/a/c", sort=1) exps <- paste( paste( res$oper, res$factor, sep="" ), collapse="" ) res <- find_factors("A*c/(x+y)/d", sort=1) exps <- paste( paste( res$oper, res$factor, sep="" ), collapse="" )
A list consisting of # of factors (nfactors), a vector of operators (oper) , a vector of factors (factor), location of each term+oper (fromto) , and ok flag.
find_factors( "a*b/c*(d-e)*f(n)" ) find_factors( c("a*b/c*(d-e)*f(n)", "-2.13*a") ) find_factors( "a%*%b/c%*%(d-e)%*%f(n)" ) find_factors( "ab%*%cd*(b%p%q+a%m%c)/c*d/a%T%b" ) # error find_factors( "a+b" )