Giter Site home page Giter Site logo

massign's Introduction


Simple matrix construction in R


What is this?

An R package with a single function: the matrix assignment operator %<-%.

Why is this?

What's simpler:

# let's create a correlation matrix!
M <- matrix(c(1, 0.2, -0.3, 0.4,
              0.2, 1, 0.6, -0.4,
              -0.3, 0.6, 1, 0.4,
              0.4, -0.4, 0.4, 1),
            nrow = 4,
            ncol = 4,
            byrow = TRUE)

or

# Showing off the lower triangular feature:
M %<-% "   1
         0.2,    1
        -0.3,  0.6,    1
         0.4, -0.4,  0.4,    1"

I like the second better. Hence Massign.

How do I install it?

# Development version
devtools::install_github("vankesteren/Massign")
library(Massign)

# CRAN (release) version
install.packages("Massign")
library(Massign)

Can you give a more formal description?

Constructing matrices for quick prototyping can be a nuisance, requiring the user to think about how to fill the matrix with values using the matrix() function. The %<-% operator solves that issue by allowing the user to construct matrices using code that shows the actual matrices.

Why the choice for %<-%?

R users may already be used to the other matrix operations like %*% and %^% (from expm). I felt this was a logical choice in that context.

What else can the package do?

#' @examples
# Basic usage
M %<-% "   1,  0.2, -0.3,  0.4
         0.2,    1,  0.6, -0.4
        -0.3,  0.6,    1,  0.4
         0.4, -0.4,  0.4,    1"

# Variables allowed!
phi <- 1.5
V %<-% "1,     1,     1
        1,   phi, phi^2
        1, phi^2, phi^4"

# We can also assign to the right:
"   1
  0.5,   1
 -0.2, 0.2,   1" %->% S

# Complex matrices work too:
C %<-% "  1+2i, 2+1i, 3+4i
        4+0.5i, 5+2i, 6+4i"

# And lastly, if you're a fan of LaTeX and one-liners:
L %<-% "1, 2, 3 \\ 4, 5, 6 \\ 7, 8, 9 \\ 10, 11, 12"
# (although this kind of defeats the WYSIWYG purpose of Massign)

Who is the target audience?

Anyone who uses R for prototyping with matrices. For example, generating data with lavaan can be made easier using Massign, or trying out different matrix operations. NB: Massign is not for programming. Due to the way the assignment operator %<-% currently works, I do not guarantee it to work once environments become a little more difficult. Use of this package as a dependency is at your own risk :)

How did you make that arrow in the logo?

That's the font Fira Code, where <- is a ligature. Check it out!

massign's People

Contributors

vankesteren avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

keesmulder guhjy

massign's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.