- Machine Learning with R Quick Start Guide
- Iván Pastor Sanz
- 141字
- 2021-06-24 16:01:31
Creating matrices
A matrix can be created by rows instead of by columns, which is done by using the byrow parameter, as follows:
m<-matrix(c(1,2,3,4,5,6), nrow=2, ncol=3,byrow=TRUE)
m
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] 4 5 6
With the dimnames parameter, column names can be added to the matrix:
m<-matrix(c(1,2,3,4,5,6), nrow=2, ncol=3,byrow=TRUE,dimnames=list(c('Obs1', 'Obs2'), c('col1', 'Col2','Col3')))
m
## col1 Col2 Col3
## Obs1 1 2 3
## Obs2 4 5 6
There are three more alternatives to creating matrices:
rbind(1:3,4:6,10:12)
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] 4 5 6
## [3,] 10 11 12
cbind(1:3,4:6,10:12)
## [,1] [,2] [,3]
## [1,] 1 4 10
## [2,] 2 5 11
## [3,] 3 6 12
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
推薦閱讀
- 現代測控系統典型應用實例
- 手把手教你學AutoCAD 2010
- Mastering Salesforce CRM Administration
- 工業機器人工程應用虛擬仿真教程:MotoSim EG-VRC
- Mastering Elastic Stack
- Creo Parametric 1.0中文版從入門到精通
- 永磁同步電動機變頻調速系統及其控制(第2版)
- 基于企業網站的顧客感知服務質量評價理論模型與實證研究
- Apache源代碼全景分析(第1卷):體系結構與核心模塊
- Learning ServiceNow
- 貫通Java Web輕量級應用開發
- 手把手教你學Photoshop CS3
- Java Deep Learning Projects
- 超好玩的Python少兒編程
- ARM嵌入式系統開發完全入門與主流實踐