- 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
推薦閱讀
- 后稀缺:自動化與未來工作
- 大數據戰爭:人工智能時代不能不說的事
- 影視后期制作(Avid Media Composer 5.0)
- 流處理器研究與設計
- Data Wrangling with Python
- 數據庫原理與應用技術
- 現代機械運動控制技術
- 運動控制器與交流伺服系統的調試和應用
- 軟件工程及實踐
- 貫通開源Web圖形與報表技術全集
- AMK伺服控制系統原理及應用
- 智能制造系統及關鍵使能技術
- 計算機應用基礎學習指導與練習(Windows XP+Office 2003)
- Hands-On Geospatial Analysis with R and QGIS
- Keras Reinforcement Learning Projects