The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Rstats - R language build on Perl

Rstats is yet experimental release. Uncompatible change will occur without warnings.

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 is called from r
  my $x1 = r->sum(c(1, 2, 3));
  
  # Register function
  r->function(my_sum => sub {
    my ($self, $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)

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

FALSE

  # FALSE
  FALSE

F

  # F
  F

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

C

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

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);