NAME

Rstats - R language build on Perl

Rstats is an experimental project, started to implement R language API in Perl, but stopped development on April 7, 2018.

SYNOPSYS

use Rstats;

# Vector
my $v1 = c_(1, 2, 3);
my $v2 = c_(3, 4, 5);

my $v3 = $v1 + v2;
print $v3;

# Sequence m:n
my $v1 = C_("1:3");

# Matrix
my $m1 = matrix(C_("1:12"), 4, 3);

# Array
my $a1 = array(C_("1:24"), c_(4, 3, 2));

# Complex
my $z1 = 1 + 2 * i_;
my $z2 = 3 + 4 * i_;
my $z3 = $z1 * $z2;

# Special value
my $true = TRUE;
my $false = FALSE;
my $na = NA;
my $nan = NaN;
my $inf = Inf;
my $null = NULL;

# all methods are called from r
my $x1 = r->sum(c_(1, 2, 3));

# Register helper
r->helper(my_sum => sub {
  my ($r, $x1) = @_;
  
  my $total = 0;
  for my $value (@{$x1->values}) {
    $total += $value;
  }
  
  return c_($total);
});
my $x2 = r->my_sum(c_(1, 2, 3));

FUNCTIONS

c_

# c(1, 2, 3)
c_(1, 2, 3)

Create vector. c_ function is equal to c of R.

C_

# 1:24
C_("1:24")

C_ function is equal to m:n of R.

array

# array(1:24, c(4, 3, 2))
array(C_("1:24"), c_(4, 3, 2))

TRUE

# TRUE
TRUE

T_

# T
T_

Alias of TRUE

FALSE

# FALSE
FALSE

F_

# F
F_

Alias of FALSE

NA

# NA
NA

NaN

# NaN
NaN

Inf

# Inf
Inf

NULL

# NULL
NULL

matrix

# matrix(1:12, 4, 3)
matrix(C_("1:12"), 4, 3)

# matrix(1:12, nrow=4, ncol=3)
matrix(C_("1:12"), {nrow => 4, ncol => 3});

# matrix(1:12, 4, 3, byrow=TRUE)
matrix(C_("1:12"), 4, 3, {byrow => TRUE});

VECTOR ACCESS

Getter

# x1[1]
$x1->get(1)

# x1[1, 2]
$x1->get(1, 2)

# x1[c(1,2), c(3,4)]
$x1->get(c_(1,2), c_(3,4))

# x1[,2]
$x1->get(NULL, 2)

# x1[-1]
$x1->get(-1)

# x1[TRUE, FALSE]
$x1->get(TRUE, FALSE)

# x1[c("id", "title")]
$x1->get(c_("id", "title"))

Setter

# x1[1] <- x2
$x1->at(1)->set($x2)

# x1[1, 2] <- x2
$x1->at(1, 2)->set($x2)

# x1[c(1,2), c(3,4)] <- x2
$x1->at(c_(1,2), c_(3,4))->set($x2)

# x1[,2] <- x2
$x1->at(NULL, 2)->set($x2)

# x1[-1] <- x2
$x1->at(-1)->set($x2)

# x1[TRUE, FALSE] <- x2
$x1->at(TRUE, FALSE)->set($x2);

# x1[c("id", "title")] <- x2
$x1->at(c_("id", "title"))->set($x2);

OPERATORS

# x1 + x2
$x1 + $x2

# x1 - x2
$x1 - $x2

# x1 * x2
$x1 * $x2

# x1 / x2
$x1 / $x2

# x1 ^ x2 (power)
$x1 ** $x2

# x1 %% x2 (remainder)
$x1 % $x2

# x1 %*% x2 (vector inner product or matrix product)
$x1 x $x2

# x1 %/% x2 (integer quotient)
r->tranc($x1 / $x2)

METHODS

abs

# abs(x1)
r->abs($x1)

acos

# acos(x1)
r->acos($x1)

acosh

# acosh(x1)
r->acosh($x1)

append

apply

Arg

array

asin

# asin(x1)
r->asin($x1)

asinh

# asinh(x1)
r->asinh($x1)

atan2

atan

# atan(x1)
r->atan($x1)

atanh

# atanh(x1)
r->atanh($x1)

c

vec

charmatch

chartr

cbind

# cbind(c(1, 2), c(3, 4), c(5, 6))
r->cbind(c_(1, 2), c_(3, 4), c_(5, 6));

ceiling

# ceiling(x1)
r->ceiling($x1)

col

# col(x1)
r->col($x1)

colMeans

# colMeans(x1)
r->colMeans($x1)

colSums

Conj

cos

# cos(x1)
r->cos($x1)

cosh

# cosh(x1)
r->cosh($x1)

cummax

cummin

cumsum

cumprod

complex

data_frame

diag

diff

exp

# exp(x1)
r->exp($x1)

expm1

# expm1(x1)
r->expm1($x1)

factor

F

FALSE

floor

# floor(x1)
r->floor($x1)

gl

grep

gsub

i

ifelse

interaction

is->element

I

Im

Inf

intersect

kronecker

length

list

log

# log(x1)
r->log($x1)

logb

# logb(x1)
r->logb($x1)

log2

# log2(x1)
r->log2($x1)

log10

# log10(x1)
r->log10($x1)

lower_tri

match

median

merge

Mod

NA

NaN

na_omit

ncol

# ncol(x1)
r->ncol($x1)

nrow

# nrow(x1)
r->nrow($x1)

NULL

numeric

matrix

max

mean

min

nchar

order

ordered

outer

paste

pi

pmax

pmin

prod

range

rank

rbind

# rbind(c(1, 2), c(3, 4), c(5, 6))
r->rbind(c_(1, 2), c_(3, 4), c_(5, 6))

Re

quantile

read->table

# read.table(...)
r->read->table(...)

rep

replace

rev

rnorm

round

# round(x1)
r->round($x1)

# round(x1, digit)
r->round($x1, $digits)

# round(x1, digits=1)
r->round($x1, {digits => TRUE});

row

# row(x1)
r->row($x1)

rowMeans

# rowMeans(x1)
r->rowMeans($x1)

rowSums

# rowSums(x1)
r->rowSums($x1)

sample

seq

sequence

set_diag

setdiff

setequal

sin

# sin(x1)
r->sin($x1)

sinh

# sinh(x1)
r->sinh($x1)

sum

sqrt

# sqrt(x1)
r->sqrt($x1)

sort

sub

subset

sweep

t

# t
r->t($x1)

tail

tan

# tan(x1)
r->tan($x1)

tanh

# tanh(x1)
r->tanh($x1)

tapply

tolower

toupper

T

TRUE

transform

trunc

# trunc(x1)
r->trunc($x1)

unique

union

upper_tri

var

which

as->array

# as.array(x1)
r->as->array($x1)

as->character

# as.character(x1)
r->as->character($x1)

as->complex

# as.complex(x1)
r->as->complex($x1)

as->integer

# as.integer(x1)
r->as->integer($x1)

as->list

# as.list
r->as->list($x1)

as->logical

# as.logical
r->as->logical($x1)

as->matrix

# as.matrix(x1)
r->as->matrix($x1)

as->numeric

# as.numeric(x1)
r->as->numeric($x1)

as->vector

# as.vector(x1)
r->as->vector($x1)

is->array

# is.array(x1)
r->is->array($x1)

is->character

# is.character(x1)
r->is->character($x1)

is->complex

# is.complex(x1)
r->is->complex($x1)

is->finite

# is.finite(x1)
r->is->finite($x1)

is->infinite

# is.infinite(x1)
r->is->infinite($x1)

is->list

# is.list(x1)
r->is->list($x1)

is->matrix

# is.matrix(x1)
r->is->matrix($x1)

is->na

# is.na(x1)
r->is->na($x1)

is->nan

# is.nan(x1)
r->is->nan($x1)

is->null

# is.null(x1)
r->is->null($x1)

is->numeric

# is.numeric(x1)
r->is->numeric($x1)

is->double

# is.double(x1)
r->is->double($x1)

is->integer

# is.integer(x1)
r->is->integer($x1)

is->logical

# is.logical(x1)
r->is->logical($x1)

is->vector

# is.vector(x1)
r->is->vector($x1)

labels

# labels(x1)
r->labels($x1)

levels

# levels(x1)
r->levels($x1)

# levels(x1) <- c("F", "M")
r->levels($x1 => c_("F", "M"))

dim

# dim(x1)
r->dim($x1)

# dim(x1) <- c(1, 2)
r->dim($x1 => c_(1, 2))

names

# names(x1)
r->names($x1)

# names(x1) <- c("n1", "n2")
r->names($x1 =>  c_("n1", "n2"))

nlevels

# nlevels(x1)
r->nlevels($x1)

dimnames

# dimnames(x1)
r->dimnames($x1)

# dimnames(x1) <- list(c("r1", "r2"), c("c1", "c2"))
r->dimnames($x1 => list(c_("r1", "r2"), c_("c1", "c2")))

colnames

# colnames(x1)
r->colnames($x1)

# colnames(x1) <- c("r1", "r2")
r->colnames($x1 => c_("r1", "r2"))

rownames

# rownames(x1)
r->rownames($x1)

# rownames(x1) <- c("r1", "r2")
r->rownames($x1 => c_("r1", "r2"))

mode

# mode(x1)
r->mode($x1)

# mode(x1) <- c("r1", "r2")
r->mode($x1 => c_("r1", "r2"))

str

# str(x1)
r->str($x1)

typeof

# typeof(x1)
r->typeof($x1);