- 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
推薦閱讀
- 大數據戰爭:人工智能時代不能不說的事
- STM32G4入門與電機控制實戰:基于X-CUBE-MCSDK的無刷直流電機與永磁同步電機控制實現
- WordPress Theme Development Beginner's Guide(Third Edition)
- 突破,Objective-C開發速學手冊
- 網中之我:何明升網絡社會論稿
- 軟件構件技術
- LMMS:A Complete Guide to Dance Music Production Beginner's Guide
- 格蠹匯編
- 嵌入式GUI開發設計
- Silverlight 2完美征程
- 青少年VEX IQ機器人實訓課程(初級)
- 智慧未來
- Unreal Development Kit Game Design Cookbook
- 單片機C51應用技術
- 大數據:從基礎理論到最佳實踐