Usage:
import betterr.baser;
This module exposes some base R functionality to D.
These functions take a single argument, and function similar to the underlying R functions. Links are to the R documentation, which provides everything you need to know. Where it applies, you can call the functions with D scalars or arrays.
These functions are the same as those above, but take an optional second argument. If set to true, NA values are removed before the calculation is done.
These functions take optional arguments. At this time, the optional arguments are a string (with comma separating arguments) that is passed directly to R. See the R documentation for the available optional arguments.
Finally, we have
seq(double from, double including, double by)
from
: Starting value of the sequenceincluding
: Ending value of the sequence - following R, included in the sequenceby
: IncrementNote that these do not need to be integers, so this function is different from R’s :
operator.
Although the primary goal of this project is to provide all of R’s functionality to D programs, relying on R for fundamental building blocks such as summation or calculating the mean will lead to a serious performance hit. As an example, look at what happens if we use the R interpreter to calculate the mean of a double[]
:
That’s not a problem if you’re going to calculate the mean of a double[100]
one time. If you’re going to calculate the mean of a double[]
holding tens of thousands of elements on the inside of a loop that’s executed a billion times, the above is ridiculously inefficient. To the extent possible, we want to make sure this type of operation is performant, so what actually happens under the hood is that the mean is calculated by Mir. The following operations currently have efficient implementations using Mir or Phobos:
double mean(double[] x)
double mean(T)(T v)
for T a Vector or Matrixdouble mean(double[] x, bool narm=false)
double mean(T)(T x, bool narm=false)
for T a Vector or Matrixdouble median(double[] x)
double median(T)(T v)
double median(string filtered, T)(T v)
for T a Vector or Matrixdouble median(double[] x, bool narm=false)
double median(T)(T x, bool narm=false)
for T a Vector or Matrixdouble sum(double[] x)
double sum(T)(T v)
for T a Vector or Matrixdouble sum(double[] x, bool narm=false)
double sum(T)(T x, bool narm=false)
for T a Vector or Matrixdouble max(double[] x)
double max(T)(T x)
for T a Vector or Matrixdouble max(double[] x, bool narm=false)
double max(T)(T x, bool narm=false)
for T a Vector or Matrixdouble min(double[] x)
double min(T)(T x)
for T a Vector or Matrixdouble min(double[] x, bool narm=false)
double min(T)(T x, bool narm=false)
for T a Vector or Matrixdouble sd(double[] x)
double sd(T)(T x)
for T a Vector or Matrixdouble sd(double[] x, bool narm=false)
double sd(T)(T x, bool narm=false)
for T a Vector or Matrixdouble var(double[] x)
double var(T)(T x)
for T a Vector or Matrixdouble var(double[] x, bool narm=false)
double var(T)(T x, bool narm=false)
for T a Vector or Matrixdouble quantile(double[] x, double p)
double quantile(double[] x, double p, bool narm)
double quantile(T)(T x, double p)
for T a Vector or Matrixdouble quantile(T)(T x, double p, bool narm)
for T a Vector or Matrixdouble[] quantile(double[] x, double[] p)
double[] quantile(T)(T x, double[] p)
for T a Vector or Matrixdouble[] quantile(double[] x, double[] p, bool narm)
double[] quantile(T)(T x, double[] p, bool narm)
for T a Vector or MatrixThe following make use of R due to lack of an alternative implementation:
double mean(double[] x, double trim=0, bool narm=false)
double mean(T)(T v, double trim=0, bool narm=false)
for T a Vector or Matrix