# Matrix Operations

June 8, 2013
By

(This article was first published on Analysis with R, and kindly contributed to R-bloggers)

Matrix manipulation in R are very useful in Linear Algebra. Below are lists of common yet important functions in dealing operations with matrices:

• Transpose – t
• Multiplication – %*%
• Determinant – det
• Inverse – solve, or ginv of MASS library
• Eigenvalues and Eigenvectors – eigen

Consider these matrices, $\left[\begin{array}{ccc}3&4&5\\2&1&3\\6&5&4\end{array}\right]$ and  $\left[\begin{array}{ccc}6&7&5\\4&5&8\\7&6&6\end{array}\right]$. In R, these would be,

Transposing these, simply use t

Now multiplying these two matrices, that would be

For the determinant, we have

Taking the inverse of matrix1 is achieved by solve or ginv R functions. Note that ginv is in MASS package,

And finally, for eigenvalues and eigenvectors simply use eigen

The output above returns the $values, which is the eigenvalues, and$vectors, the eigenvectors.

More about matrix here.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

## Recent popular posts

Contact us if you wish to help support R-bloggers, and place your banner here.

# Never miss an update! Subscribe to R-bloggers to receive e-mails with the latest R posts.(You will not see this message again.)

Click here to close (This popup will not appear again)