Rstats - R language build on Perl
Rstats is yet experimental release. Uncompatible change will occur without warnings.
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));
# c(1, 2, 3) c(1, 2, 3)
# 1:24 C('1:24')
C function is equal to m:n of R.
m:n
# array(1:24, c(4, 3, 2)) array(C('1:24'), c(4, 3, 2))
# TRUE TRUE
# T T
# FALSE FALSE
# F F
# NA NA
# NaN NaN
# Inf Inf
# NULL NULL
# 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});
# 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"))
# 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);
# 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)
# abs(x1) r->abs($x1)
# acos(x1) r->acos($x1)
# acosh(x1) r->acosh($x1)
# asin(x1) r->asin($x1)
# asinh(x1) r->asinh($x1)
# atan(x1) r->atan($x1)
# atanh(x1) r->atanh($x1)
# cbind(c(1, 2), c(3, 4), c(5, 6)) r->cbind(c(1, 2), c(3, 4), c(5, 6));
# ceiling(x1) r->ceiling($x1)
# col(x1) r->col($x1)
# colMeans(x1) r->colMeans($x1)
# cos(x1) r->cos($x1)
# cosh(x1) r->cosh($x1)
# exp(x1) r->exp($x1)
# expm1(x1) r->expm1($x1)
# floor(x1) r->floor($x1)
# log(x1) r->log($x1)
# logb(x1) r->logb($x1)
# log2(x1) r->log2($x1)
# log10(x1) r->log10($x1)
# ncol(x1) r->ncol($x1)
# nrow(x1) r->nrow($x1)
# rbind(c(1, 2), c(3, 4), c(5, 6)) r->rbind(c(1, 2), c(3, 4), c(5, 6))
# round(x1) r->round($x1) # round(x1, digit) r->round($x1, $digits) # round(x1, digits=1) r->round($x1, {digits => TRUE});
# row(x1) r->row($x1)
# rowMeans(x1) r->rowMeans($x1)
# rowSums(x1) r->rowSums($x1)
# sin(x1) r->sin($x1)
# sinh(x1) r->sinh($x1)
# sqrt(x1) r->sqrt($x1)
# t r->t($x1)
# tan(x1) r->tan($x1)
# tanh(x1) r->tanh($x1)
# trunc(x1) r->trunc($x1)
# as.array(x1) r->as_array($x1)
# as.character(x1) r->as_character($x1)
# as.complex(x1) r->as_complex($x1)
# as.integer(x1) r->as_integer($x1)
# as.list r->as_list($x1)
# as.logical r->as_logical($x1)
# as.matrix(x1) r->as_matrix($x1)
# as.numeric(x1) r->as_numeric($x1)
# as.vector(x1) r->as_vector($x1)
# is.array(x1) r->is_array($x1)
# is.character(x1) r->is_character($x1)
# is.complex(x1) r->is_complex($x1)
# is.finite(x1) r->is_finite($x1)
# is.infinite(x1) r->is_infinite($x1)
# is.list(x1) r->is_list($x1)
# is.matrix(x1) r->is_matrix($x1)
# is.na(x1) r->is_na($x1)
# is.nan(x1) r->is_nan($x1)
# is.null(x1) r->is_null($x1)
# is.numeric(x1) r->is_numeric($x1)
# is.double(x1) r->is_double($x1)
# is.integer(x1) r->is_integer($x1)
# is.logical(x1) r->is_logical($x1)
# is.vector(x1) r->is_vector($x1)
# labels(x1) r->labels($x1)
# levels(x1) r->levels($x1) # levels(x1) <- c("F", "M") r->levels($x1 => c("F", "M"))
# dim(x1) r->dim($x1) # dim(x1) <- c(1, 2) r->dim($x1 => c(1, 2))
# names(x1) r->names($x1) # names(x1) <- c("n1", "n2") r->names($x1 => c("n1", "n2"))
# nlevels(x1) r->nlevels($x1)
# 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(x1) r->colnames($x1) # colnames(x1) <- c("r1", "r2") r->colnames($x1 => c("r1", "r2"))
# rownames(x1) r->rownames($x1) # rownames(x1) <- c("r1", "r2") r->rownames($x1 => c("r1", "r2"))
# mode(x1) r->mode($x1) # mode(x1) <- c("r1", "r2") r->mode($x1 => c("r1", "r2"))
# str(x1) r->str($x1)
# typeof(x1) r->typeof($x1);
To install Rstats, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Rstats
CPAN shell
perl -MCPAN -e shell install Rstats
For more information on module installation, please visit the detailed CPAN module installation guide.