public class R
extends java.lang.Object
Rank.
Otherwise, SuanShu implements it as a static utility function.
SuanShu uses the same (or similar) names and syntax whenever possible as in R to allow easy conversion from R code.| Modifier and Type | Class and Description |
|---|---|
static interface |
R.ifelse
Return a value with the same shape as
test
which is filled with elements selected from either yes or no
depending on whether the element of test is true or false. |
static interface |
R.which
Decide whether x satisfies the
boolean test. |
| Modifier and Type | Method and Description |
|---|---|
static double[] |
cumsum(double[] arr)
Get the cumulative sums of the elements in an array.
|
static int[] |
cumsum(int[] arr)
Get the cumulative sums of the elements in an array.
|
static double[] |
diff(double[] arr)
Get the first differences of an array.
|
static double[][] |
diff(double[][] arr)
Get the first differences of an array of vectors.
|
static double[][] |
diff(double[][] arr,
int lag,
int order)
Get the lagged and iterated differences of vectors.
|
static double[] |
diff(double[] arr,
int lag,
int order)
Get the lagged and iterated differences.
|
static double[] |
ifelse(double[] arr,
R.ifelse selection)
Return a value with the same shape as
test
which is filled with elements selected from either yes or no
depending on whether the element of test is true or false. |
static int[] |
order(double[] arr)
Sort an array in ascending order.
|
static int[] |
order(double[] arr,
boolean ascending)
Sort an array either in ascending or descending order.
|
static java.lang.String |
paste(java.util.Collection<java.lang.String> collection,
java.lang.String delimiter)
Concatenate
Strings into one String. |
static double[] |
rep(double value,
int times)
Generate an array of
doubles of repeated values. |
static int[] |
rep(int value,
int times)
Generate an array of
ints of repeated values. |
static double[] |
select(double[] arr,
R.which test)
Select the array elements which satisfy the
boolean test. |
static int[] |
select(int[] arr,
R.which test)
Select the array elements which satisfy the
boolean test. |
static double[] |
seq(double from,
double to,
double inc)
Generate a sequence of
doubles from from up to to with increments inc. |
static int[] |
seq(int from,
int to)
Generate a sequence of
ints from from up to to with increments 1. |
static int[] |
seq(int from,
int to,
int inc)
Generate a sequence of
ints from from up to to with increments inc. |
static double[] |
subarray(double[] arr,
int[] indices)
Get a sub-array of the original array with the given indices.
|
static int[] |
subarray(int[] arr,
int[] indices)
Get a sub-array of the original array with the given indices.
|
static int[] |
which(double[] arr,
R.which test)
Get the indices of the array elements which satisfy the
boolean test. |
static int[] |
which(int[] arr,
R.which test)
Get the indices of the array elements which satisfy the
boolean test. |
public static double[] rep(double value,
int times)
doubles of repeated values.value - the repeated valuetimes - the length of the arraypublic static int[] rep(int value,
int times)
ints of repeated values.value - the repeated valuetimes - the length of the arraypublic static double[] seq(double from,
double to,
double inc)
doubles from from up to to with increments inc.
The last number in the sequence is smaller than or equal to to for positive inc.
The last number in the sequence is bigger than or equal to to for negative inc.from - the first number in the sequenceto - the bound of the sequenceinc - the incrementdoublespublic static int[] seq(int from,
int to,
int inc)
ints from from up to to with increments inc.
The last number in the sequence is smaller than or equal to to for positive inc.
The last number in the sequence is bigger than or equal to to for negative inc.from - the first number in the sequenceto - the bound of the sequenceinc - the incrementintspublic static int[] seq(int from,
int to)
ints from from up to to with increments 1.
That is, [from, to], inclusively.from - the first number in the sequenceto - the bound of the sequenceintspublic static double[] diff(double[] arr,
int lag,
int order)
arr - an array, double[]lag - an integer indicating which lag to useorder - an integer indicating the order of the difference.
This is the number of times diff is applied to the data.
E.g., diff(x, 1, 2) = diff(diff(x, 1, 1), 1, 1).public static double[] diff(double[] arr)
arr - an array, double[]public static double[][] diff(double[][] arr,
int lag,
int order)
arr - a double[][]; row view; must not be jaggedlag - an integer indicating which lag to useorder - an integer indicating the order of the difference.
This is the number of times diff is applied to the data.
E.g., diff(x, 1, 2) = diff(diff(x, 1, 1), 1, 1).public static double[][] diff(double[][] arr)
arr - a double[][]; row view; must not be jaggedpublic static double[] cumsum(double[] arr)
arr - an array, double[]cumsumpublic static int[] cumsum(int[] arr)
arr - an array, int[]cumsumpublic static double[] ifelse(double[] arr,
R.ifelse selection)
test
which is filled with elements selected from either yes or no
depending on whether the element of test is true or false.arr - an arrayselection - the boolean test to decide true or false and return valuespublic static int[] which(double[] arr,
R.which test)
boolean test.arr - an array. double[]test - the boolean test to decide true or false (which to select)public static int[] which(int[] arr,
R.which test)
boolean test.arr - an array. int[]test - the boolean test to decide true or false (which to select)public static double[] select(double[] arr,
R.which test)
boolean test.
R does not have a 'select' function. The R-equivalent is arr[which(...]}.arr - an array, double[]test - the boolean test to determine which elements to be selectedpublic static int[] select(int[] arr,
R.which test)
boolean test.
R does not have a 'select' function. The R-equivalent is arr[which(...]}.arr - an array, int[]test - the boolean test to determine which elements to be selectedpublic static double[] subarray(double[] arr,
int[] indices)
arr[indices].arr - an array, double[]indices - an array of indices to selectarr[indices].public static int[] subarray(int[] arr,
int[] indices)
arr[indices].arr - an array, int[]indices - an array of indices to selectarr[indices].public static int[] order(double[] arr,
boolean ascending)
arr - an array, int[]ascending - true if arranging elements in ascending order; false if descending orderpublic static int[] order(double[] arr)
arr - an array, int[]public static java.lang.String paste(java.util.Collection<java.lang.String> collection,
java.lang.String delimiter)
Strings into one String.collection - the collection of strings to be concatenateddelimiter - the separation symbol for the strings