search.cpan.org is shutting down
Josh Ballard > Statistics-RVector > Statistics::RVector
Module Version: 0.1

# NAME

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

# DESCRIPTION

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..

# SYNOPSIS

```        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```

# EXPORT

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

# TODO

* 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.

# METHODS

## VECTOR CREATION

### 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

### \$vector->name(\$index)

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

## VECTOR MODIFICATION/DUPLICATION OPERATIONS

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.

### \$vector->clone()

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

### \$vector->extend(\$len)

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

## VECTOR INSPECTION OPERATIONS

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.

### \$vector->length()

Returns the integer length of the vector.

### \$vector->range()

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

### \$vector->max()

Returns the maximum value in the vector.

### \$vector->min()

Returns the minimum value in the vector.

### \$vector->sum()

Returns the arithmetic sum of all entries in the vector.

### \$vector->prod()

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

### \$vector->mean()

Returns the arithmetic mean of the vector values.

### \$vector->var()

Returns the sample variance of the vector values.

### \$vector->sd()

Returns the sample standard deviation of the vector values.

### as_array(\$vector)

Returns an array reference to the values in the vector.

### to_string(\$vector)

Returns a pretty-printed string of the vector values

### vectorpower(\$val1,\$val2,\$switch)

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.

# AUTHOR

Josh Ballard <josh@oofle.com>