- Machine Learning with R Quick Start Guide
- Iván Pastor Sanz
- 174字
- 2021-06-24 16:01:31
Matrix functions
Furthermore, there are specific functions for matrices:
- The following function extracts the diagonal as a vector:
m<-matrix(c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3)
m
## [,1] [,2] [,3]
## [1,] 1 4 7
## [2,] 2 5 8
## [3,] 3 6 9
diag(m)
## [1] 1 5 9
- Returns the dimensions of a matrix:
dim(m)
## [1] 3 3
- Returns the sum of columns of a matrix:
colSums(m)
## [1] 6 15 24
- Returns the sum of rows of a matrix:
rowSums(m)
## [1] 12 15 18
- The transpose of a matrix can be obtained using the following code:
t(m)
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] 4 5 6
## [3,] 7 8 9
- Returns the determinant of a matrix:
det(m)
## [1] 0
- The auto-values and auto-vectors of a matrix are obtained using the following code:
eigen(m)
## eigen() decomposition
## $values
## [1] 1.611684e+01 -1.116844e+00 -5.700691e-16
##
## $vectors
## [,1] [,2] [,3]
## [1,] -0.4645473 -0.8829060 0.4082483
## [2,] -0.5707955 -0.2395204 -0.8164966
## [3,] -0.6770438 0.4038651 0.4082483
推薦閱讀
- 數(shù)控銑削(加工中心)編程與加工
- 自主研拋機(jī)器人技術(shù)
- 21天學(xué)通Visual Basic
- 運(yùn)動(dòng)控制系統(tǒng)應(yīng)用與實(shí)踐
- 精通數(shù)據(jù)科學(xué):從線性回歸到深度學(xué)習(xí)
- 人工智能:語(yǔ)言智能處理
- INSTANT VMware vCloud Starter
- Learn QGIS
- 基于Quartus Ⅱ的數(shù)字系統(tǒng)Verilog HDL設(shè)計(jì)實(shí)例詳解
- Flash CS3動(dòng)畫(huà)制作
- 大話數(shù)據(jù)科學(xué):大數(shù)據(jù)與機(jī)器學(xué)習(xí)實(shí)戰(zhàn)(基于R語(yǔ)言)
- 網(wǎng)絡(luò)規(guī)劃與設(shè)計(jì)
- Learn T-SQL Querying
- 數(shù)字中國(guó):大數(shù)據(jù)與政府管理決策
- 單片機(jī)技術(shù)