ternary.apply: Apply a function over a ternary grid
Description
Given 1) a ternary grid and 2) a function that takes a ternary value as its first argument, this function returns a vector formed by applying the function to each point in the grid.
Usage
ternary.apply(grid, f, ...)
Arguments
grid
A data frame with columns a, b and c specifying points in a ternary field
f
A function that accepts a length 3 vector as its first argument
...
Additional arguments passed to f
Value
A vector of results
Details
Results will be concatenated into a vector; it is most useful for scalar-valued functions.
## The function is currently defined asfunction(grid, f, ...)
{
f = match.fun(f)
abc = grid[,letters[1:3]]
g = function(i) f(abc[i,], ...)
unlist(lapply(1:nrow(grid), g))
}