Use lambda expressions in rlist functions
masterMost functions in rlist that accept expressions support several forms of lambda expressions using the ~ syntax. This allows for more complex logic using the element (x), its index (i), or its name (name).
Supported Forms:
- Implicit:
expression(uses default symbols.,.i, and.name) - Univariate:
x ~ expressionorf(x) ~ expression(wherexis the list member) - Multivariate:
f(x,i) ~ expressionorf(x,i,name) ~ expression(whereiis the index andnameis the name)
Examples:
# Using implicit lambda with . for the element
list.map(nums, c(min=min(.), max=max(.)))
# Using univariate lambda with x
list.filter(nums, x ~ mean(x) >= 3)
# Using multivariate lambda with x and i
list.map(nums, f(x,i) ~ sum(x,i))list.map(nums, c(min=min(.),max=max(.)))
list.filter(nums, x ~ mean(x)>=3)
list.map(nums, f(x,i) ~ sum(x,i))