Expression functions
Functions in Phibble\Expr that build expressions for filter(), mutate(), arrange(), and summarise(), and the methods of Expr objects.
Columns and literals
col()
col(string $name): ColReference to the column with the given name.
A plain PHP string passed to a helper is a literal; col() is how an expression reads a column.
| Parameter | Type | Default | Description |
|---|---|---|---|
$name |
string |
The column name. |
Function in Phibble\Expr
Returns Col
Examples phibble for Laravel developers, phibble
lit()
lit(mixed $value): LitLiteral value as an expression.
A date or datetime literal is typed as a date when its time of day is midnight, and as a datetime otherwise.
| Parameter | Type | Default | Description |
|---|---|---|---|
$value |
mixed |
Null, a bool, int, float, or string, a DateTimeInterface, a Phibble\Time, or a list of scalars. |
Function in Phibble\Expr
Returns Lit
Throws InvalidArgumentException: when the value is of another type, or a list holds a value that is not a scalar.
call()
call(string $fn, mixed ...$args): CallCall to any registered function by name, such as call(‘str_sub’, col('s'), 1, 3).
String keys in $args become named options; other arguments are positional. Values that are not expressions are wrapped as literals.
| Parameter | Type | Default | Description |
|---|---|---|---|
$fn |
string |
The registered function name, as listed in Functions::REGISTRY. | |
...$args |
mixed |
Positional arguments, then named options. |
Function in Phibble\Expr
Returns Call
Throws InvalidArgumentException: when the function is not registered, the number of positional arguments is out of range, or a named option is not allowed.
desc()
desc(Expr|string $expr): DescDescending sort key for arrange(), the first argument of a ranking function, or order_by.
desc() is rejected anywhere else in an expression.
| Parameter | Type | Default | Description |
|---|---|---|---|
$expr |
Expr|string |
An expression, or a column name. |
Function in Phibble\Expr
Returns Desc
Operators
Expr->add()
$expr->add(mixed $other): CallSum of this expression and $other.
NA gives NA. Adding a period such as days(1) to a date or datetime uses clock arithmetic, and adding seconds or a time to a time gives a time.
| Parameter | Type | Default | Description |
|---|---|---|---|
$other |
mixed |
An expression or literal. |
Method of Phibble\Expr\Expr
Returns Call
Examples Expressions, Types
Expr->sub()
$expr->sub(mixed $other): CallDifference of this expression and $other.
NA gives NA. Subtracting a date from a date gives days, a datetime from a datetime gives seconds, and a period from a date or datetime uses clock arithmetic.
| Parameter | Type | Default | Description |
|---|---|---|---|
$other |
mixed |
An expression or literal. |
Method of Phibble\Expr\Expr
Returns Call
Examples Expressions, Getting started
Expr->mul()
$expr->mul(mixed $other): CallProduct of this expression and $other.
NA gives NA. A period or time multiplied by a number is scaled.
| Parameter | Type | Default | Description |
|---|---|---|---|
$other |
mixed |
An expression or literal. |
Method of Phibble\Expr\Expr
Returns Call
Examples Getting started, SQL tables
Expr->div()
$expr->div(mixed $other): CallQuotient of this expression and $other, always a float.
NA gives NA. Division by zero gives Inf or -Inf, and 0 / 0 gives NaN, as in R.
| Parameter | Type | Default | Description |
|---|---|---|---|
$other |
mixed |
An expression or literal. |
Method of Phibble\Expr\Expr
Returns Call
Examples Expressions, Getting started, SQL tables
Expr->mod()
$expr->mod(mixed $other): CallRemainder of this expression divided by $other, with the sign of $other.
R’s %% operator: the remainder after floored division. NA gives NA. An integer remainder by zero is NA, and a float remainder by zero NaN.
| Parameter | Type | Default | Description |
|---|---|---|---|
$other |
mixed |
An expression or literal. |
Method of Phibble\Expr\Expr
Returns Call
Examples Expressions
Expr->pow()
$expr->pow(mixed $other): CallThis expression raised to the power $other, as a float.
R’s ^ operator. NA gives NA.
| Parameter | Type | Default | Description |
|---|---|---|---|
$other |
mixed |
An expression or literal. |
Method of Phibble\Expr\Expr
Returns Call
Expr->neg()
$expr->neg(): CallNegation of this expression.
NA gives NA.
Method of Phibble\Expr\Expr
Returns Call
Expr->eq()
$expr->eq(mixed $other): CallWhether this expression equals $other.
R’s == operator. NA on either side gives NA. Numbers and logicals compare numerically, dates and datetimes by instant, and other values as strings.
| Parameter | Type | Default | Description |
|---|---|---|---|
$other |
mixed |
An expression or literal. |
Method of Phibble\Expr\Expr
Returns Call
Examples Reading and writing data, Expressions, Getting started
Expr->ne()
$expr->ne(mixed $other): CallWhether this expression differs from $other.
R’s != operator. NA on either side gives NA. Numbers and logicals compare numerically, dates and datetimes by instant, and other values as strings.
| Parameter | Type | Default | Description |
|---|---|---|---|
$other |
mixed |
An expression or literal. |
Method of Phibble\Expr\Expr
Returns Call
Examples Getting started
Expr->lt()
$expr->lt(mixed $other): CallWhether this expression is less than $other.
R’s < operator. NA on either side gives NA. Numbers and logicals compare numerically, dates and datetimes by instant, and other values as strings, byte by byte.
| Parameter | Type | Default | Description |
|---|---|---|---|
$other |
mixed |
An expression or literal. |
Method of Phibble\Expr\Expr
Returns Call
Expr->le()
$expr->le(mixed $other): CallWhether this expression is less than or equal to $other.
R’s <= operator. NA on either side gives NA. Numbers and logicals compare numerically, dates and datetimes by instant, and other values as strings, byte by byte.
| Parameter | Type | Default | Description |
|---|---|---|---|
$other |
mixed |
An expression or literal. |
Method of Phibble\Expr\Expr
Returns Call
Examples Expressions
Expr->gt()
$expr->gt(mixed $other): CallWhether this expression is greater than $other.
R’s > operator. NA on either side gives NA. Numbers and logicals compare numerically, dates and datetimes by instant, and other values as strings, byte by byte.
| Parameter | Type | Default | Description |
|---|---|---|---|
$other |
mixed |
An expression or literal. |
Method of Phibble\Expr\Expr
Returns Call
Examples Expressions, Types, Getting started
Expr->ge()
$expr->ge(mixed $other): CallWhether this expression is greater than or equal to $other.
R’s >= operator. NA on either side gives NA. Numbers and logicals compare numerically, dates and datetimes by instant, and other values as strings, byte by byte.
| Parameter | Type | Default | Description |
|---|---|---|---|
$other |
mixed |
An expression or literal. |
Method of Phibble\Expr\Expr
Returns Call
Examples Expressions
Expr->and()
$expr->and(mixed $other): CallLogical AND of this expression and $other.
R’s & operator, with three-valued logic: false wins over NA, and NA with true gives NA.
| Parameter | Type | Default | Description |
|---|---|---|---|
$other |
mixed |
A logical expression or literal. |
Method of Phibble\Expr\Expr
Returns Call
Examples Expressions, Getting started
Expr->or()
$expr->or(mixed $other): CallLogical OR of this expression and $other.
R’s | operator, with three-valued logic: true wins over NA, and NA with false gives NA.
| Parameter | Type | Default | Description |
|---|---|---|---|
$other |
mixed |
A logical expression or literal. |
Method of Phibble\Expr\Expr
Returns Call
Examples Expressions
Expr->not()
$expr->not(): CallLogical negation of this expression.
R’s ! operator. NA gives NA.
Method of Phibble\Expr\Expr
Returns Call
Examples Expressions, phibble
Expr->isNa()
$expr->isNa(): CallWhether each value is NA.
NaN counts as NA. Equivalent to is_na().
Method of Phibble\Expr\Expr
Returns Call
Examples phibble
Expr->isIn()
$expr->isIn(array $values): CallWhether each value is one of the given values.
R’s %in% operator. Dates, datetimes, and times compare by value. NA matches only when the list holds null. The result is never NA.
| Parameter | Type | Default | Description |
|---|---|---|---|
$values |
list<mixed> |
The values to match: null, scalars, or dates, datetimes, or times of one kind. |
Method of Phibble\Expr\Expr
Returns Call
Throws InvalidArgumentException: when a value is another type, or the list mixes scalars with temporal values or times with dates.
Examples Expressions, SQL tables
Expr->between()
$expr->between(mixed $low, mixed $high): CallWhether each value lies between $low and $high, inclusive.
NA in the value or either bound gives NA. Equivalent to between().
| Parameter | Type | Default | Description |
|---|---|---|---|
$low |
mixed |
The lower bound. | |
$high |
mixed |
The upper bound. |
Method of Phibble\Expr\Expr
Returns Call
Examples Getting started, SQL tables
Expr->desc()
$expr->desc(): DescDescending sort key on this expression, for arrange(), the first argument of a ranking function, or order_by.
Equivalent to desc().
Method of Phibble\Expr\Expr
Returns Desc
Conditionals and missing values
is_na()
is_na(mixed $x): CallWhether each value is NA.
NaN counts as NA.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A column expression, such as col('x'), or a literal. |
Function in Phibble\Expr
Returns Call
if_else()
if_else( mixed $condition, mixed $true, mixed $false, mixed ...$options,): CallValue of $true where the condition holds and of $false where it does not.
| Parameter | Type | Default | Description |
|---|---|---|---|
$condition |
mixed |
A logical expression. | |
$true |
mixed |
The value where the condition is true. | |
$false |
mixed |
The value where the condition is false. | |
...$options |
mixed |
Named options: missing (mixed, default NA) is the value where the condition is NA. |
Function in Phibble\Expr
Returns Call
case_when()
case_when(mixed ...$args): CallValue paired with the first condition that holds, as case_when(cond1, value1, cond2, value2, ..., default: value).
Conditions are tested in order per row; an NA condition does not match.
| Parameter | Type | Default | Description |
|---|---|---|---|
...$args |
mixed |
Condition and value pairs, then named options: default (mixed, default NA) is the value where no condition holds. |
Function in Phibble\Expr
Returns Call
Throws InvalidArgumentException: when the positional arguments do not form condition and value pairs.
coalesce()
coalesce(mixed ...$args): CallFirst value that is not NA among the arguments, row by row.
NaN counts as NA and is skipped, as in is_na() and R’s coalesce().
| Parameter | Type | Default | Description |
|---|---|---|---|
...$args |
mixed |
One or more expressions or literals. |
Function in Phibble\Expr
Returns Call
between()
between(mixed $x, mixed $low, mixed $high): CallWhether each value lies between $low and $high, inclusive.
The result is NA where $x, $low, or $high is NA.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A column expression, such as col('x'), or a literal. |
|
$low |
mixed |
The lower bound. | |
$high |
mixed |
The upper bound. |
Function in Phibble\Expr
Returns Call
na_if()
na_if(mixed $x, mixed $y): CallValues of $x, with NA where $x equals $y.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A column expression, such as col('x'), or a literal. |
|
$y |
mixed |
The value to replace with NA. |
Function in Phibble\Expr
Returns Call
near()
near(mixed $x, mixed $y, mixed ...$options): CallWhether $x and $y are equal within a tolerance.
The result is NA where either value is NA.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric expression or literal. | |
$y |
mixed |
A numeric expression or literal. | |
...$options |
mixed |
Named options: tol (float, default sqrt(PHP_FLOAT_EPSILON), about 1.5e-8) is the tolerance; an absolute difference below it counts as equal. |
Function in Phibble\Expr
Returns Call
Math
abs()
abs(mixed $x): CallAbsolute value.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric expression or literal. |
Function in Phibble\Expr
Returns Call
sqrt()
sqrt(mixed $x): CallSquare root.
The square root of a negative number is NaN.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric expression or literal. |
Function in Phibble\Expr
Returns Call
exp()
exp(mixed $x): CallExponential function, e raised to the power $x.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric expression or literal. |
Function in Phibble\Expr
Returns Call
log()
log(mixed $x, mixed ...$options): CallLogarithm, natural by default.
The logarithm of 0 is -Inf, and of a negative number NaN.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric expression or literal. | |
...$options |
mixed |
Named options: base (float, default e) is the base of the logarithm. |
Function in Phibble\Expr
Returns Call
log10()
log10(mixed $x): CallBase-10 logarithm.
The logarithm of 0 is -Inf, and of a negative number NaN.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric expression or literal. |
Function in Phibble\Expr
Returns Call
round()
round(mixed $x, mixed ...$options): CallValue rounded to a number of decimal digits.
Rounding follows R 4.0 and later: the candidate nearer the stored double wins, and exact ties go to the even digit, so round(2.675, digits: 2) is 2.67. Integers are returned unchanged when digits is 0 or more. SQL backends evaluate it in memory.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric expression or literal. | |
...$options |
mixed |
Named options: digits (int, default 0) is the number of decimal places; a negative value rounds to tens, hundreds, and so on. |
Function in Phibble\Expr
Returns Call
floor()
floor(mixed $x): CallLargest whole number not greater than the value, as a float.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric expression or literal. |
Function in Phibble\Expr
Returns Call
ceiling()
ceiling(mixed $x): CallSmallest whole number not less than the value, as a float.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric expression or literal. |
Function in Phibble\Expr
Returns Call
Conversion
as_int()
as_int(mixed $x): CallValues converted to integers.
R’s as.integer().
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A column expression, such as col('x'), or a literal. |
Function in Phibble\Expr
Returns Call
as_float()
as_float(mixed $x): CallValues converted to floats.
R’s as.double().
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A column expression, such as col('x'), or a literal. |
Function in Phibble\Expr
Returns Call
as_string()
as_string(mixed $x): CallValues converted to strings.
R’s as.character(). SQL backends evaluate it in memory.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A column expression, such as col('x'), or a literal. |
Function in Phibble\Expr
Returns Call
as_bool()
as_bool(mixed $x): CallValues converted to logicals.
R’s as.logical(). SQL backends evaluate it in memory.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A column expression, such as col('x'), or a literal. |
Function in Phibble\Expr
Returns Call
Aggregates
n()
n(): CallNumber of rows in the group.
Function in Phibble\Expr
Returns Call
Examples phibble for Laravel developers, phibble
sum()
sum(mixed $x, mixed ...$options): CallSum of the values.
The result is NA when a value is NA, unless na_rm is true. The sum is an integer when every value is an integer or logical, and 0 for no values. The sum of times is a time.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric expression. | |
...$options |
mixed |
Named options: na_rm (bool, default false) drops NA first. |
Function in Phibble\Expr
Returns Call
Throws InvalidArgumentException: at evaluation, when the values are dates or datetimes.
mean()
mean(mixed $x, mixed ...$options): CallMean of the values.
The result is NA when a value is NA, unless na_rm is true, and NaN for no values. The mean of dates is a date, of datetimes a datetime, and of times a time.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric or temporal expression. | |
...$options |
mixed |
Named options: na_rm (bool, default false) drops NA first. |
Function in Phibble\Expr
Returns Call
Examples phibble for Laravel developers, phibble
median()
median(mixed $x, mixed ...$options): CallMedian of the values.
The result is NA when a value is NA, unless na_rm is true, and NA for no values. The median of dates is a date, of datetimes a datetime, and of times a time.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric or temporal expression. | |
...$options |
mixed |
Named options: na_rm (bool, default false) drops NA first. |
Function in Phibble\Expr
Returns Call
Examples phibble
min()
min(mixed $x, mixed ...$options): CallSmallest of the values.
The result is NA when a value is NA, unless na_rm is true, NaN when a value is NaN, and Inf for no values. Strings compare byte by byte.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A column expression, such as col('x'), or a literal. |
|
...$options |
mixed |
Named options: na_rm (bool, default false) drops NA first. |
Function in Phibble\Expr
Returns Call
max()
max(mixed $x, mixed ...$options): CallLargest of the values.
The result is NA when a value is NA, unless na_rm is true, NaN when a value is NaN, and -Inf for no values. Strings compare byte by byte.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A column expression, such as col('x'), or a literal. |
|
...$options |
mixed |
Named options: na_rm (bool, default false) drops NA first. |
Function in Phibble\Expr
Returns Call
Examples phibble for Laravel developers
sd()
sd(mixed $x, mixed ...$options): CallSample standard deviation of the values.
The divisor is n - 1, and the result is NA for fewer than two values. The result is NA when a value is NA, unless na_rm is true. Dates are measured in days, and datetimes and times in seconds.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric or temporal expression. | |
...$options |
mixed |
Named options: na_rm (bool, default false) drops NA first. |
Function in Phibble\Expr
Returns Call
var_()
var_(mixed $x, mixed ...$options): CallSample variance of the values.
R’s var(); the trailing underscore avoids PHP’s reserved word. The divisor is n - 1, and the result is NA for fewer than two values. The result is NA when a value is NA, unless na_rm is true. Dates are measured in days, and datetimes and times in seconds.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric or temporal expression. | |
...$options |
mixed |
Named options: na_rm (bool, default false) drops NA first. |
Function in Phibble\Expr
Returns Call
quantile()
quantile(mixed $x, mixed $p, mixed ...$options): CallSample quantile of the values at probability $p.
Uses R’s default method (type 7), interpolating between order statistics. The quantile of datetimes is a datetime, and of times a time.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric or temporal expression. | |
$p |
mixed |
The probability, from 0 to 1. | |
...$options |
mixed |
Named options: na_rm (bool, default false) drops NA first. |
Function in Phibble\Expr
Returns Call
Throws InvalidArgumentException: at evaluation, when a value is NA and na_rm is false, or when the values are dates.
iqr()
iqr(mixed $x, mixed ...$options): CallInterquartile range of the values: the 0.75 quantile minus the 0.25 quantile.
R’s IQR(). Quantiles use R’s default method (type 7). The result is NA for no values. Dates are measured in days, and datetimes and times in seconds.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric or temporal expression. | |
...$options |
mixed |
Named options: na_rm (bool, default false) drops NA first. |
Function in Phibble\Expr
Returns Call
Throws InvalidArgumentException: at evaluation, when a value is NA and na_rm is false.
n_distinct()
n_distinct(mixed ...$args): CallNumber of distinct values, or of distinct combinations across several arguments.
NA counts as a distinct value unless na_rm is true.
| Parameter | Type | Default | Description |
|---|---|---|---|
...$args |
mixed |
One or more expressions, then named options: na_rm (bool, default false) skips rows where any argument is NA. |
Function in Phibble\Expr
Returns Call
first()
first(mixed $x, mixed ...$options): CallFirst value in the group.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A column expression, such as col('x'), or a literal. |
|
...$options |
mixed |
Named options: default (mixed, default NA) is returned when the group has no values; order_by (expression, default row order) sorts the values first, NA last, and accepts desc(); na_rm (bool, default false) drops NA first. |
Function in Phibble\Expr
Returns Call
last()
last(mixed $x, mixed ...$options): CallLast value in the group.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A column expression, such as col('x'), or a literal. |
|
...$options |
mixed |
Named options: default (mixed, default NA) is returned when the group has no values; order_by (expression, default row order) sorts the values first, NA last, and accepts desc(); na_rm (bool, default false) drops NA first. |
Function in Phibble\Expr
Returns Call
nth()
nth(mixed $x, mixed $n, mixed ...$options): CallValue at position $n in the group.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A column expression, such as col('x'), or a literal. |
|
$n |
mixed |
The 1-based position; a negative position counts from the end. | |
...$options |
mixed |
Named options: default (mixed, default NA) is returned when the position is 0 or out of range; order_by (expression, default row order) sorts the values first, NA last, and accepts desc(); na_rm (bool, default false) drops NA first. |
Function in Phibble\Expr
Returns Call
any()
any(mixed $x, mixed ...$options): CallWhether any value is true.
With NA present and na_rm false, the result is true when some value is true, and NA otherwise. The result is false for no values.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A logical expression. | |
...$options |
mixed |
Named options: na_rm (bool, default false) drops NA first. |
Function in Phibble\Expr
Returns Call
all()
all(mixed $x, mixed ...$options): CallWhether every value is true.
With NA present and na_rm false, the result is false when some value is false, and NA otherwise. The result is true for no values.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A logical expression. | |
...$options |
mixed |
Named options: na_rm (bool, default false) drops NA first. |
Function in Phibble\Expr
Returns Call
Window functions
lag()
lag(mixed $x, mixed ...$options): CallValue from n rows earlier in the group.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A column expression, such as col('x'), or a literal. |
|
...$options |
mixed |
Named options: n (int, default 1) is the offset; default (mixed, default NA) fills rows with no earlier row; order_by (expression, default row order) sets the order, NA last, and accepts desc(). |
Function in Phibble\Expr
Returns Call
lead()
lead(mixed $x, mixed ...$options): CallValue from n rows later in the group.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A column expression, such as col('x'), or a literal. |
|
...$options |
mixed |
Named options: n (int, default 1) is the offset; default (mixed, default NA) fills rows with no later row; order_by (expression, default row order) sets the order, NA last, and accepts desc(). |
Function in Phibble\Expr
Returns Call
row_number()
row_number(mixed $x = null): CallRow number within the group, or the rank of each value with ties broken by row order.
With no argument, rows are numbered 1 to n in their order. With an argument, NA values get NA, and a factor column ranks by level order.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
null |
An expression to rank by, or desc() of one. Omit it to number rows in order. |
Function in Phibble\Expr
Returns Call
Throws ArgumentCountError: when given more than one argument.
min_rank()
min_rank(mixed $x): CallRank of each value, ties sharing the lowest rank, with gaps after ties.
NA values get NA. A factor column ranks by level order.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
An expression to rank by, or desc() of one. |
Function in Phibble\Expr
Returns Call
dense_rank()
dense_rank(mixed $x): CallRank of each value, ties sharing a rank, with no gaps after ties.
NA values get NA. A factor column ranks by level order.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
An expression to rank by, or desc() of one. |
Function in Phibble\Expr
Returns Call
percent_rank()
percent_rank(mixed $x): CallMinimum rank rescaled to the range 0 to 1: (min_rank - 1) / (m - 1), where m is the number of non-NA values.
NA values get NA. With one non-NA value, the result is NaN.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
An expression to rank by, or desc() of one. |
Function in Phibble\Expr
Returns Call
cume_dist()
cume_dist(mixed $x): CallCumulative distribution: the share of non-NA values less than or equal to each value.
NA values get NA.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
An expression to rank by, or desc() of one. |
Function in Phibble\Expr
Returns Call
ntile()
ntile(mixed $x = null, ?int $n = null): CallBucket number from 1 to n, splitting the ordered values into n groups as evenly as possible.
Earlier buckets take the extra rows when the sizes differ. NA values get NA. Without $x, rows are bucketed in row order.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
null |
An expression to order by, or desc() of one. Null or omitted buckets rows in order. |
$n |
int|null |
null |
The number of buckets. Required. |
Function in Phibble\Expr
Returns Call
Throws InvalidArgumentException: when n is not given.
Throws ArgumentCountError: when given more than two arguments.
cumsum()
cumsum(mixed $x): CallCumulative sum in row order.
Once a value is NA, every later result is NA.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric expression. |
Function in Phibble\Expr
Returns Call
cumprod()
cumprod(mixed $x): CallCumulative product in row order.
Once a value is NA, every later result is NA. SQL backends evaluate it in memory.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric expression. |
Function in Phibble\Expr
Returns Call
cummean()
cummean(mixed $x): CallCumulative mean in row order.
Once a value is NA, every later result is NA.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A numeric expression. |
Function in Phibble\Expr
Returns Call
cummin()
cummin(mixed $x): CallCumulative minimum in row order.
Once a value is NA, every later result is NA.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A column expression, such as col('x'), or a literal. |
Function in Phibble\Expr
Returns Call
cummax()
cummax(mixed $x): CallCumulative maximum in row order.
Once a value is NA, every later result is NA.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A column expression, such as col('x'), or a literal. |
Function in Phibble\Expr
Returns Call
cumall()
cumall(mixed $x): CallWhether every value so far, in row order, is true.
Once a value is false, every later result is false. After an NA, results are NA until a false value appears.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A logical expression. |
Function in Phibble\Expr
Returns Call
cumany()
cumany(mixed $x): CallWhether any value so far, in row order, is true.
Once a value is true, every later result is true. After an NA, results are NA until a true value appears.
| Parameter | Type | Default | Description |
|---|---|---|---|
$x |
mixed |
A logical expression. |
Function in Phibble\Expr
Returns Call
consecutive_id()
consecutive_id(mixed ...$args): CallRun identifier that starts at 1 and increases each time the value, or combination of values, changes from the previous row.
SQL backends evaluate it in memory.
| Parameter | Type | Default | Description |
|---|---|---|---|
...$args |
mixed |
One or more expressions. |
Function in Phibble\Expr
Returns Call
Expression objects
Expr::of()
Expr::of(mixed $value): ExprPHP value wrapped as a literal expression; an expression is returned unchanged.
| Parameter | Type | Default | Description |
|---|---|---|---|
$value |
mixed |
An expression, or a value lit() accepts. |
Static method of Phibble\Expr\Expr
Returns Expr
Throws InvalidArgumentException: when the value is not one lit() accepts.
Expr::fromArray()
Expr::fromArray(array $node): ExprExpression rebuilt from the array form that toArray() returns.
| Parameter | Type | Default | Description |
|---|---|---|---|
$node |
array<string, mixed> |
A node as toArray() gives it. |
Static method of Phibble\Expr\Expr
Returns Expr
Throws InvalidArgumentException: when a node has an unknown type, a literal is invalid, or a call does not fit the function registry.
Examples Expressions
Expr->toArray()
$expr->toArray(): arrayJSON-friendly description of the expression tree.
Expr::fromArray() rebuilds the expression from it.
Method of Phibble\Expr\Expr
Returns array<string, mixed>
Examples Expressions
Expr->columns()
$expr->columns(): arrayNames of the columns the expression reads, in order of first use.
Method of Phibble\Expr\Expr
Returns list<string>
Examples Expressions