Functions can be used anywhere in DataGraph that accepts numerical values. Use them in Expression variables or Expression columns. Function input can be numbers, variables, or column names.

Functions operate on individual values or values within the same row, or row operations. For column operations, see the list of built-in column properties that perform calculations for a column of numbers.

## Examples

Some functions accept multiple inputs (i.e., a list of numbers). For example, the sum function can accept multiple inputs with commas in between such that: sum(1,2,3) = 6.

The List of Input functions are useful for row operations across multiple columns. For example, the row by row sum of three columns A, B, and C can be computed as: sum(A,B,C).

The remaining functions have a specified number of input arguments. For example, the standard functions have one input and one output, sin(0.5) = 0.47943. If a column with multiple entries is input, then the output will be computed on a row by row basis.

## List of Inputs

These functions act on a list of numbers any length. Using these functions, you can perform calculations for values in the same row across multiple columns. For example, if you have three columns named A, B, and C, you can sum the values in each row by entering, sum(A,B,C) in an Expression column.

min | minimum of two or more arguments. min(3,5) = 3, min(3,5,2) = 2. |

max | maximum of two or more arguments; max(3,5) = 5, max(3,5,2) = 5. |

mean | mean of two or more arguments; mean(3,5,2) = 3.3333. |

median | median of two or more arguments; median(3,5,2) = 3. |

sd | sample standard deviation; sd(3,5,2) = 1.5275. |

sum | the sum of two or more arguments; sum(3,5,2) = 10. |

norm | norm of a vector, norm(3,5) = sqrt(3^2 + 5^2), norm(3,5,1) = sqrt(3^2 + 5^2 + 1^2) |

## Standard Functions

Function input can be numbers, variables, or column names. When the input is a column with n row values, the function will output n results.

sin | sin in radians |

cos | cos in radians |

tan | tan(x) = sin(x)/cos(x) in radians |

asin | inverse of sin(x) |

acos | inverse of cos(x) |

atan | inverse of tan(x) |

angle | angle(x,y) = the angle that the line (0,0) to (x,y) makes with the positive x axis. The angle is in radians. That means that angle(cos(x),sin(x)) = x for x from -π,π. angle(-1,0) is π. This is better than using the inverse of tan (atan) because it will deal with the sign properly. NOTE: This function is equivalent to atan2(y,x), used by some software. |

sinh | hyperbolic sin, sinh(x) = (exp(x)-exp(-x))/2 |

cosh | hyperbolic cos, cosh(x) = (exp(x)+exp(-x))/2 |

tanh | hyberbolic tan, tanh(x) = sinh(x)/cosh(x) |

sinc | sinc(x) = sin(x)/x when x≠0, and 1 when x==0. |

sqrt | square root of a number |

cbrt | cube root of a number |

exp | exponent of a number, exp(x) = e^x. |

log | natural logarithm, the inverse of exp(x) |

log1p | log1p(x) = log(1+x) |

log10 | base 10 logarithm, inverse of 10^x |

log2 | base 2 logarithm, inverse of 2^x |

abs | absolute value of a number, or the number without its sign. |

sgn | sgn(x) is the sign of x. sgn(x) = -1 if x<0, sgn(0) = 0, and sgn(x) = 1 if x>0. |

## Integers & Rounding

floor | floor(x) is the largest integer value less than or equal to x. floor(4.5) = 4 floor(-4.5) = -5; |

ceil | ceil(x) is the smallest integer value greater than or equal to x. ceil(4.5) = 5 ceil(-4.5) = -4; |

round | round(x) rounds x to the nearest integer; round(4.5) = 5, round(-4.5) = -5. round(x,d) rounds a to a specified number of digits, d; round(3.225,1) = 3.2. Half points are rounded away from zero. |

mod | Remainder after division. mod(9,4) = 1 because 9 = 4*2 + 1. Works also for fractions, mod(9.2,0.5) = 0.2, because 9.2 = n*0.5 + 0.2 where n is 18. |

## Logical Functions

if | if(a,b,c) where it returns b if a is non-zero and c if a is zero. Example: if(x<3,valueIfTrue,valueIfFalse) |

isfinite | isfinte(a) where it returns 1 when a is finite (number), where 0 when a is NaN. |

isnan | isnan(a) where it returns 1 when a is NaN (which stands for not a number), or returns 0 otherwise. Works for nan or NAN, not case sensitive. |

## Special Functions

gamma | the Gamma function, https://en.wikipedia.org/wiki/Gamma_function |

loggamma | loggamma(x) = log(gamma(x)), needed because the gamma function increases rapidly |

fact | Factorial of the number. Returns NAN if the argument is not an integer. Note that fact(n) = gamma(n+1), so far large values you can compute log(fact(n)) by using loggamma(n+1). So if you want to compute n!/( (n-k)! * k!) when n is too large, you can use exp( loggamma(n+1) – loggamma(n-k+1) – loggamma(k+1)) |

erf | Error function, integral of exp(-t^2) from 0 to infinity, scaled so that the asymptotes at +/- ∞ are +/- 1. https://en.wikipedia.org/wiki/Error_function |

erfc | Complementary error function erfc(x) = 1.0-erf(x). So erfc(x) is very close to 0 if x is large, and is more accurate than using 1.0-erf(x). |

lambertw | Lambert W function also known as the product logarithm. Returns the principal branch of the function. https://en.wikipedia.org/wiki/Lambert_W_function |

j0 | One of the Bessel functions – https://en.wikipedia.org/wiki/Bessel_function. j0(x) = Bessel function of the first kind of order 0 of x. |

j1 | Bessel function of the first kind of order 1. |

jn | jn(n,x) = Bessel function of the first kind of order n of x. |

y0 | Bessel function of the second kind of order 0 of x. |

y1 | Bessel function of the second kind of order 1 of x. |

yn | yn(n,x) = Bessel function of the second kind of order n of x. |

## Piecewise Functions

rect | rect(x) = 1 if (|x|<0.5, 0.5 if x=+/- 0.5 and 0 if |x|>0.5 |

tri | tri(x) = 0 if |x|>1, tri(x) = 1-|x| if |x|≤1. |

H | H(x) = 0 if x<0, H(0) = 0.5, H(x) = 1 if x>0 |

## Ternary Functions

The ternary functions calculate the relative amounts of three values and map them from a three coordinate system (a,b,c) into the corresponding x and y locations in a cartesian coordinate system. One function provides the x location and another function provides the y location. The (x,y) output from the ternary functions can be used in any drawing commands (e.g., points, plot).

ternaryX | ternaryX(a,b,c) = x location in a ternary diagram centered at 0,0. |

ternaryY | ternaryY(a,b,c) = y location in a ternary diagram centered at 0,0. |

NOTE: The bottom left corner is the relative value of “a”, or where “a = 1”. The values for “a,b,c” move counterclockwise around the triangle. To flip the triangle in the vertical direction, place a negative in front of the functions.

## Date & Time Functions

The Date column internally uses a Unix or POSIX time format (seconds since Jan 1st 1970). The following functions allow you to create date columns, or manipulate existing date columns to pull various values from them (e.g., week, month, …) using an Expression column.

NOTE: hour is from 0 to 24 (24 means the next day).

seconds | Combine individual date/time values (from Number columns) to create a single proper date column. Examples: seconds(year,month,day) – midnight at the start of a given day seconds(year,month,day,hour,minute) – a specific day/time seconds(year,month,day,hour,minute,seconds) – include seconds |

year | The argument is a POSIX time, and what is returned is the year for that date |

month | The argument is a POSIX time, and what is returned is the month for that date |

day | The argument is a POSIX time, and what is returned is the day for that date |

dayofweek | The argument is a POSIX time. Returns 1 for a Monday, 7 for Sunday |

dayofyear | The argument is a POSIX time, and what is returned is the day in that year, with Jan 1st equal to 1. |

week | The input is a POSIX time Week number – see https://en.wikipedia.org/wiki/ISO_week_date |

weekyear | Input is a POSIX time. Computes the year for the week, to match with the week(x) functionality. |

hour | Input is a POSIX time, returns the hour |

minute | Input is a POSIX time, returns the minute |

second | Input is a POSIX time, returns the second. Same as mod(x,60) |

isAM | Input is a POSIX time, returns 1 if the hour is <12, 0 otherwise. |

isPM | Input is a POSIX time, returns 1 if the hour is ≥12, 0 otherwise. |

## Statistical Functions

The functions for generating random numbers (**rand** and **nrand**) are only available in the Expression column. The other functions can be used in Expression columns or Expression variables.

tcdf | tcdf(x,df) the cumulative distribution function from the Student’s t distribution, at specified degrees of freedom (df) |

tpdf | tpdf(x,df) the probability density function (pdf) from the Student’s t distribution, at specified degrees of freedom (df) |

tinv | tinv(p,df) inverse of the cumulative distribution function from the Student’s t distribution, at specified probability (p) and degrees of freedom (df) |

rand | rand(a,b) returns a random number between a and b |

nrand | returns a random number sampled from a normal distribution. Examples: nrand(sd), mean of zero and standard deviation (sd) or nrand (x,sd) mean of x and standard deviation (sd). |