Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/krzjoa/matricks

Useful tricks for matrix manipulation.
https://github.com/krzjoa/matricks

algebra matrix matrix-manipulation r

Last synced: 2 months ago
JSON representation

Useful tricks for matrix manipulation.

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# matricks
> Useful tricks for matrix manipulation

[![CRAN status](https://www.r-pkg.org/badges/version/matricks)](https://CRAN.R-project.org/package=matricks)
[![Documentation](https://img.shields.io/badge/documentation-matricks-orange.svg?colorB=E91E63)](http://krzjoa.github.io/matricks)
[![Travis build status](https://travis-ci.org/krzjoa/matricks.svg?branch=master)](https://travis-ci.org/krzjoa/matricks)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/krzjoa/matricks?branch=master&svg=true)](https://ci.appveyor.com/project/krzjoa/matricks)
[![Buy hex stciker](https://img.shields.io/badge/buy%20hex-matricks-green)](https://www.redbubble.com/people/krzjoa/works/43111073-matricks-r-package-hex?asc=u&kind=sticker&p=sticker&size=small)

### Installation
`matricks` is available on CRAN, so you can install it using simply:
```{r,message=FALSE, results='hide', eval=FALSE}
install.packages('matricks')
```
If you rather want to install dev version, you can do it with `devtools`.
```{r install.dev, message=FALSE, results='hide', eval=FALSE}
devtools::install_github('krzjoa/matricks')
```

### Usage
Main `matricks` functions are `m` and `v`, which provide convenient API to create matrices and vectors.
Why should we write:
```{r matrix_function}
matrix(c(5, 6, 7,
8, 0, 9,
3, 7, 1), nrow = 3, byrow = TRUE)
```
if we can simply create such a matrix like that:
```{r m_function}
library(matricks)

m(5, 6, 7|
8, 0, 9|
3, 7, 1)
```

`v` function is an useful shortcut for creating vertical vectors (single columns)
```{r v_function}
v(1,2,3)
v(1:5)
```

Setting values in easier with `matricks`
```{r set_values_function}
mat <- matrix(0, 3, 3)
set_values(mat, c(1, 2) ~ 0.5, c(3, 1) ~ 7)
```