|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.misc.R
public class R
This class collects some R-equivalent utility functions.
Most of the R-equivalent functions are implemented as classes, e.g., Rank.
The functions listed here are the commonly used utility function rather than mathematical concepts.
We try to use the same names and syntax whenever possible as in R to allow easier conversion from R code.
| Nested Class Summary | |
|---|---|
static interface |
R.ifelse
the placeholder for R.ifelse |
static interface |
R.which
the placeholder for R.which |
| Method Summary | |
|---|---|
static double[] |
cumsum(double[] arr)
Get an array whose elements are the cumulative sum of the elements of the input array. |
static int[] |
cumsum(int[] arr)
Get an array whose elements are the cumulative sum of the elements of the input 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 difference)
Get the lagged and iterated differences of vectors. |
static double[] |
diff(double[] arr,
int lag,
int difference)
Get the lagged and iterated differences. |
static double[] |
ifelse(double[] arr,
R.ifelse selection)
Get an array with the same length as arr
which is filled with either "yes" or "no" values
according to the boolean/binary classification in R.ifelse. |
static int[] |
order(double[] arr)
Get a permutation which rearranges an array into ascending order. |
static int[] |
order(double[] arr,
boolean ascending)
Get a permutation which rearranges an array into ascending or descending order. |
static java.lang.String |
paste(java.util.AbstractCollection<java.lang.String> collection,
java.lang.String delimiter)
Concatenate Strings into one String. |
static double[] |
rep(double value,
int times)
This generates an array of doubles of repeated values. |
static int[] |
rep(int value,
int times)
This generates an array of ints of repeated values. |
static double[] |
select(double[] arr,
R.which criterion)
Select the array elements which satisfy the boolean criterion. |
static int[] |
select(int[] arr,
R.which criterion)
Select the array elements which satisfy the boolean criterion. |
static double[] |
seq(double from,
double to,
double inc)
This generates a sequence of doubles from from up to to with increments inc. |
static int[] |
seq(int from,
int to)
This generates a sequence of ints from from to to with increments 1. |
static int[] |
seq(int from,
int to,
int inc)
This generates a sequence of doubles from from up to to with increments inc. |
static double[] |
subarray(double[] arr,
int[] indices)
Get a subarray of the original array with the given indices. |
static int[] |
subarray(int[] arr,
int[] indices)
Get a subarray of the original array with the given indices. |
static int[] |
which(double[] arr,
R.which criterion)
Get the indices of the array elements which satisfy the boolean criterion. |
static int[] |
which(int[] arr,
R.which criterion)
Get the indices of the array elements which satisfy the boolean criterion. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static double[] rep(double value,
int times)
value - the repeated valuetimes - the length of the array
public static int[] rep(int value,
int times)
value - the repeated valuetimes - the length of the array
public static double[] seq(double from,
double to,
double inc)
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 increment
public static int[] seq(int from,
int to,
int inc)
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 increment
public static int[] seq(int from,
int to)
from to to with increments 1.
That is, [from, to], inclusively.
from - the first number in the sequenceto - the bound of the sequence
public static double[] diff(double[] arr,
int lag,
int difference)
arr - a double[] arraylag - an integer indicating which lag to usedifference - 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).
diff(arr, lag, difference)public static double[] diff(double[] arr)
arr - a double[] array
diff(arr)
public static double[][] diff(double[][] arr,
int lag,
int difference)
arr - a double[][] array; row view; cannot be jaggedlag - an integer indicating which lag to usedifference - 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).
diff(arr, lag, difference)public static double[][] diff(double[][] arr)
arr - a double[][] array; row view; cannot be jagged
diff(arr)public static double[] cumsum(double[] arr)
arr - a double[] array
cumsum(arr)public static int[] cumsum(int[] arr)
arr - a int[] array
cumsum(arr)
public static double[] ifelse(double[] arr,
R.ifelse selection)
arr
which is filled with either "yes" or "no" values
according to the boolean/binary classification in R.ifelse.
arr - an input double[] arrayselection - the classification criterion to decide true or false for a number
ifelse values
public static int[] which(double[] arr,
R.which criterion)
arr - a double[] arraycriterion - determines which elements to select
public static int[] which(int[] arr,
R.which criterion)
arr - a double[] arraycriterion - determines which elements to select
public static double[] select(double[] arr,
R.which criterion)
R does not have a 'select' function. It is equivalent to:
arr[which(...}]
arr - a double[] arraycriterion - determines which elements to select
public static int[] select(int[] arr,
R.which criterion)
R does not have a 'select' function. It is equivalent to:
arr[which(...}]
arr - a double[] arraycriterion - determines which elements to select
public static double[] subarray(double[] arr,
int[] indices)
arr[indices].
arr - a double[] arrayindices - an array of indices to select
arr[indices]
public static int[] subarray(int[] arr,
int[] indices)
arr[indices].
arr - a int[] arrayindices - an array of indices to select
arr[indices]
public static int[] order(double[] arr,
boolean ascending)
arr - a double[] arrayascending - true if arranging elements in ascending order; false if descending order
public static int[] order(double[] arr)
arr - a double[] array
public static java.lang.String paste(java.util.AbstractCollection<java.lang.String> collection,
java.lang.String delimiter)
collection - the set of strings to be concatenateddelimiter - the separation symbol for the strings
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||