calcCore {GCDkit} | R Documentation |
Calculates a user-defined parameter specified by the equation.
calcCore(equation, where = "WR", redo = TRUE)
equation |
a text string to be evaluated. |
where |
which matrix should be used? |
redo |
logical; should be the routine called again and again? |
This is a core calculation function.
The expression specified by 'equation
' can involve any combination of
names of existing numerical columns in the matrix 'where
', numbers
(i.e. constants), arithmetic operators +-*/^
and R functions.
The most useful of the latter are 'sqrt
' (square root), 'log
'
(natural logarithm), 'log10
' (common logarithm),
'exp
' (exponential function), 'sin
',
'cos
' and 'tan
' (trigonometric functions).
Potentially useful can be also
min
(minimum),
max
(maximum),
length
(number of elements/cases),
'sum
' (sum of the elements),
'mean
' (mean of the elements),
and 'prod
' (product of the elements).
However, any user-defined function can be also invoked here.
For most statistical functions, an useful parameter 'na.rm=T
' can be specified.
This makes the function to calculate the result from the available data only,
ignoring the not determined value (see Examples).
The quotation marks in 'equation
' need to preceded by a backslash.
Option 'redo
' specifies whether the routine should be called repeatedly
until some meaningful result is obtained. Otherwise 'NA
' is returned.
A list of three items:
equation |
equation as entered by the user |
results |
numeric vector with the results or NA if none can be calculated |
formula |
the unevaluated expression corresponding to the ' |
Vojtěch Janoušek, vojtech.janousek@geology.cz
data(blatna) accessVar("blatna") calcCore("SiO2/10") calcCore("Na2O+K2O") calcCore("log10(Na2O+K2O)") calcCore("SiO2/MW[\"SiO2\"]") # dividing by the built-in molecularWeight, NB the backslashes calcCore("length(MgO)") calcCore("mean(MgO,na.rm=TRUE)") # na.rm is a safety measure in case some missing values are present # otherwise the result would be 'NA'