- 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
推薦閱讀
- ABB工業(yè)機器人編程全集
- 21小時學(xué)通AutoCAD
- Design for the Future
- Getting Started with Clickteam Fusion
- 分布式多媒體計算機系統(tǒng)
- C語言寶典
- 西門子變頻器技術(shù)入門及實踐
- Chef:Powerful Infrastructure Automation
- 激光選區(qū)熔化3D打印技術(shù)
- 軟件構(gòu)件技術(shù)
- 電氣控制與PLC原理及應(yīng)用(歐姆龍機型)
- 單片機技術(shù)項目化原理與實訓(xùn)
- 生成對抗網(wǎng)絡(luò)項目實戰(zhàn)
- Deep Learning Essentials
- 網(wǎng)站規(guī)劃與網(wǎng)頁設(shè)計