Learn R Programming

⚠️There's a newer version (0.4.0) of this package.Take me there.

ramify

Package ramify provides additional matrix functionality for R including: (1) wrappers for the base matrix function that allows matrices to be created from character strings and lists (the former is especially useful for creating block matrices), (ii) better default printing of large matrices, and (iii) a number of convenience functions for users more familiar with other scientific languages like Julia, MATLAB/Octave, or Python.

The main function in this package is mat, an extention to the built-in matrix function. Many convenience functions are also available, for example:

  • bmat - like mat, but constructs a block matrix.
  • dmat - like mat, but returns a data frame instead of a matrix.
  • argmax/argmin - find the position of the max/min in each row or column of a matrix
  • eye - construct an identity matrix
  • hcat/vcat - concatenate matrices
  • fill - fill a matrix or array with a particular value
  • flatten - flatten (i.e., collapse) a matrix or array to one dimension
  • inv - calculate the inverse of a square matrix
  • linspace/logspace - construct a vector of linearly-spaced/logarithmically-spaced elements
  • meshgrid - construct matrices for evaluating functions over rectangular 2-D grids (useful for contour plots)
  • ones/zeros - construct a matrix or array of all ones/zeros
  • rand/randi/randn - construct a matrix or array of uniformly/normally distributed random numbers
  • resize - change the size and shape of a given matrix or array
  • size - extract the dimensions of a matrix or array.
  • trues/falses - construct a matrix or array of all TRUEs/FALSEs

ramify introduces a pretty print function called pprint. This is a generic function. Ordinarily, matrices are printed completely on the screen which is not very helpful when the dimensions are large. Using the pprint function, however, allows you to see a more efficient printed version of the matrix. For example,

> library(ramify)
> m <- randn(1000, 1000)  # matrix filled with a million normal random deviates
> pprint(m)  # compare this output to `print(m)` and `head(m)`
# 1000 by 1000 matrix of doubles 
# 
#            [,1]    [,2]    [,3] ... [,1000]
# [1,]     0.0385 -0.0620 -0.0930 ...  1.9295
# [2,]    -2.5014  0.3277  1.1657 ... -0.6824
# [3,]    -0.1308 -0.9673  0.6388 ... -0.2852
# ...         ...     ...     ... ...     ...
# [1000,]  0.4980  0.6902  1.4920 ... -2.7023

This can be useful for viewing large (numeric) data frames too:

> data(Boston, package = "MASS")  # Boston housing data
> pprint(Boston)
# 506 by 14 matrix of doubles 
# 
#       crim      zn   indus ...    medv
# 1   0.0063 18.0000  2.3100 ... 24.0000
# 2   0.0273  0.0000  7.0700 ... 21.6000
# 3   0.0273  0.0000  7.0700 ... 34.7000
# ...    ...     ...     ... ...     ...
# 506 0.0474  0.0000 11.9300 ... 11.9000

This printing behavior was partially inspired by the "tbl_df" class for data frames provided by the dplyr package.

Installation

You can install the latest stable release from CRAN:

install.packages("ramify")

The development version is hosted on GitHub at https://github.com/bgreenwell/ramify and can be downloaded using devtools:

# Assuming devtools is already installed
devtools::install_github("bgreenwell/ramify")

Bug reports should be submitted to https://github.com/bgreenwell/ramify/issues.

Copy Link

Version

Install

install.packages('ramify')

Monthly Downloads

477

Version

0.3.2

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Brandon Greenwell

Last Published

August 19th, 2015

Functions in ramify (0.3.2)

atleast_2d

View Input as an Array with at Least Two Dimensions.
linspace

Linearly-spaced Elements
flatten

Flatten Matrices/Arrays
mat

Matrices
is.triu

Upper Triangular Matrix Test
fill

Fill a Matrix
tri

Lower/Upper Triangular Matrix
ramify

ramify: additional matrix functionality
inv

Matrix Inverse
argmax

Row/Column Max/Min Indices
triu

Extract Upper Triangular Matrix
bmat

Block Matrices
tril

Extract Lower Triangular Matrix
randn

Matrix/Array of Normal Random Numbers
eye

Identity Matrix
pprint

Pretty Printing
randi

Matrix/Array of Uniform Random Integers
logspace

Logarithmically-spaced Elements
add_dots

Shorten a Vector
resize

Resize Matrices and Arrays
tr

Trace of a Matrix
hcat

Concatenate Matrices
desc_mat

Describe a Matrix
meshgrid

Rectangular 2-D Grid
rand

Matrix/Array of Uniform Random Numbers
dmat

Data Frames
size

Dimensions of a Matrix/Array
is.tril

Lower Triangular Matrix Test