Learn R Programming

Manipulation of high-dimensional arrays in R with the magic package

Overview

The magic package implements functionality for manipulating high-dimensional arrays using efficient vectorised methods. The original application was high-dimensional magic hypercubes. This README shows some of the more useful functions in the package.

Installation

You can install the released version of magic from CRAN with:

# install.packages("magic")  # uncomment this to install the package
library("magic")

Package highlights

  • Function adiag() binds arbitrarily-dimensioned arrays corner-to-corner
  • Function apad() pads arbitrarily-dimensioned arrays
  • Function apldrop() is a replacement for APL’s drop
  • Function aplus() superimposes two arrays of different dimensions and returns the sum of overlapping elements
  • Function arev() is a multidimensional generalization of rev()
  • Function arot() is a generalization of matlab’s rotdim
  • Function fnsd() returns the first nonsingleton dimension of an arbitrary dimensioned array
  • Function ashift() shifts the origin of arbitrary dimensioned arrays

Much of the package functionality is vectorised in array dimension.

Further information

For more detail, see the package vignette

vignette("magic")

Copy Link

Version

Install

install.packages('magic')

Monthly Downloads

21,296

Version

1.6-1

License

GPL-2

Issues

Pull Requests

Stars

Forks

Maintainer

Robin K S Hankin

Last Published

November 16th, 2022

Functions in magic (1.6-1)

adiag

Binds arrays corner-to-corner
aplus

Generalized array addition
allsums

Row, column, and two diagonal sums of arrays
allsubhypercubes

Subhypercubes of magic hypercubes
fnsd

First non-singleton dimension
cube2

A pantriagonal magic cube
diag.off

Extracts broken diagonals
is.magichypercube

magic hypercubes
cilleruelo

A class of multiplicative magic squares due to Cilleruelo and Luca
eq

Comparison of two magic squares
magic.product

Product of two magic squares
is.magic

Various tests for the magicness of a square
hudson

Pandiagonal magic squares due to Hudson
magic.prime

Magic squares prime order
latin

Random latin squares
magiccube.2np1

Magic cubes of order 2n+1
do.index

Apply a function to array element indices
force.integer

Integerize array elements
as.standard

Standard form for magic squares
arow

Generalized row and col
circulant

Circulant matrices of any order
is.square.palindromic

Is a square matrix square palindromic?
lozenge

Conway's lozenge algorithm for magic squares
magichypercube.4n

Magic hypercubes of order 4n
is.ok

does a vector have the sum required to be a row or column of a magic square?
magicplot

Joins consecutive numbers of a magic square.
minmax

are all elements of a vector identical?
magiccubes

Magic cubes of order 3
notmagic.2n

An unmagic square
magic

Creates magic squares
hendricks

A perfect magic cube due to Hendricks
magic.constant

Magic constant of a magic square or hypercube
hadamard

Hadamard matrices
magic.4np2

Magic squares of order 4n+2
process

Force index arrays into range
recurse

Recursively apply a permutation
magic-package

tools:::Rd_package_title("magic")
sam

Sparse antimagic squares
shift

Shift origin of arrays and vectors
panmagic.8

Panmagic squares of order 8
panmagic.6npm1

Panmagic squares of order 4n, 6n+1 and 6n-1
magic.2np1

Magic squares of odd order
magic.4n

Magic squares of order 4n
perfectcube5

A perfect magic cube of order 5
magic.8

Regular magic squares of order 8
perfectcube6

A perfect cube of order 6
transf

Frenicle's equivalent magic squares
nqueens

N queens problem
panmagic.4

Panmagic squares of order 4
strachey

Strachey's algorithm for magic squares
subsums

Sums of submatrices
arev

Reverses some dimensions; a generalization of rev
apad

Pad arrays
Frankenstein

A perfect magic cube due to Frankenstein
arot

Rotates an array about two specified dimensions
apl

Replacements for APL functions take and drop
Ollerenshaw

A most perfect square due to Ollerenshaw