Josh Ballard > Statistics-RVector-0.1 > Statistics::RVector



Annotate this POD

View/Report Bugs
Module Version: 0.1   Source  


Statistics::RVector - Mathematical/statistical vector implementation mimicking that of R stats


The RVector class is a perl implementation of the base R stats language mathematical vector to enable better statistical/numerical/mathematical analysis of data in Perl. This implementation is still very beta, but should work sufficiently for vector arithmetic (+,-,*,/,**), as well as calculating sum(), mean(), var(), and sd(), which are the sum of the values, the mean of the values, the variance of the sample, and the standard deviation of the sample..


        use Statistics::RVector;
        my $x = rv(10.4, 5.6, 3.1, 6.4, 21.7);
        my $y = Statistics::RVector->new($vector1,0,$vector1);
        my $v = 2 * $x + $y + 1


Exports the function rv() by default, which is a shortened form of Statistics::RVector->new().


* Handle non-numerical and/or invalid (i.e. division by zero) cases in all functions.

* Add support for naming of entries in the vector.

* Lots of other things that I still don't understand about R that I'm sure other people will want to use.



Statistics::RVector->new() / rv()

Creates a new RVector object. For example, syntax of rv(10,17,24) would create a vector containing 3 entries of 10, 17, and 24 in that order.


Adds a new entry to the vector in question, including an (optional) name to be added to the name table to fetch the value


Returns the name of a given index in the vector, if given.


Below are functions which allow for modification and/or duplication of a vector. These operations will result in either a modification to the existing vector, or the return of a new vector altogether.


Returns an exact copy of the original vector in different memory. Allows for modification without affecting the original vector.


Extends the length of the given vector to length $len, filling all new values with repeated values from the existing array in the same offsets.

For example, an rv(1,2,3) that is extended to 8 will then be rv(1,2,3,1,2,3,1,2).


Below are the various operations that you can perform on a single vector object. They will return in most cases numerical values unless otherwise specified. They do not in any way change the vector, nor create any new vectors.


Returns the integer length of the vector.


Returns a vector holding the largest and smallest values in the specified vector.


Returns the maximum value in the vector.


Returns the minimum value in the vector.


Returns the arithmetic sum of all entries in the vector.


Returns the arithmetic product of all the entries in the vector.


Returns the arithmetic mean of the vector values.


Returns the sample variance of the vector values.


Returns the sample standard deviation of the vector values.



Returns an array reference to the values in the vector.


Returns a pretty-printed string of the vector values






These are the functions called by the overloaded mathematical operators when interacting with an RVector object. These represent +, -, *, /, and ** respectively. They take in two objects to perform the arithmetic operations on and a value for whether the value order has actually been switched, since the RVector object should always come first. $switch is only relevant to subtraction, division, and power.


Josh Ballard <>


Copyright (c) 2010 Josh Ballard.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.


For more information about RVector, see and follow the link to RVector. For more information about the R Stats programming language, see

syntax highlighting: