- Machine Learning with R Quick Start Guide
- Iván Pastor Sanz
- 122字
- 2021-06-24 16:01:31
Accessing elements in a matrix
You can access the elements in a matrix in a similar way to how you accessed elements of a vector using indexing. However, the elements here would be the index number of rows and columns.
Here a some examples of accessing elements:
- If you want to access the element at a second column and first row:
m<-array(c(1,2,3,4,5,6), dim=c(2,3))
m
## [,1] [,2] [,3]
## [1,] 1 3 5
## [2,] 2 4 6
m[1,2]
## [1] 3
- Similarly, accessing the element at the second column and second row:
m[2,2]
## [1] 4
- Accessing the elements in only the second row:
m[2,]
## [1] 2 4 6
- Accessing only the first column:
m[,1]
## [1] 1 2
推薦閱讀
- Microsoft Dynamics CRM Customization Essentials
- Mastercam 2017數(shù)控加工自動編程經(jīng)典實(shí)例(第4版)
- Natural Language Processing Fundamentals
- 手把手教你學(xué)AutoCAD 2010
- VMware Performance and Capacity Management(Second Edition)
- 21天學(xué)通C++
- Hands-On Cybersecurity with Blockchain
- 分布式多媒體計算機(jī)系統(tǒng)
- Windows游戲程序設(shè)計基礎(chǔ)
- 西門子變頻器技術(shù)入門及實(shí)踐
- Excel 2007技巧大全
- 工業(yè)機(jī)器人維護(hù)與保養(yǎng)
- LAMP網(wǎng)站開發(fā)黃金組合Linux+Apache+MySQL+PHP
- TensorFlow Reinforcement Learning Quick Start Guide
- 在實(shí)戰(zhàn)中成長:Windows Forms開發(fā)之路