- Mastering Data Analysis with R
- Gergely Daróczi
- 87字
- 2021-07-09 21:58:54
Transposing matrices
One of the most used, but often not mentioned, methods for restructuring data is transposing matrices. This simply means switching the columns with rows and vice versa, via the t
function:
> (m <- matrix(1:9, 3)) [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 > t(m) [,1] [,2] [,3] [1,] 1 2 3 [2,] 4 5 6 [3,] 7 8 9
Of course, this S3
method also works with data.frame
, and actually, with any tabular object. For more advanced features, such as transposing a multi-dimensional table, take a look at the aperm
function from the base
package.
推薦閱讀
- Expert C++
- 數(shù)據(jù)庫原理及應用(Access版)第3版
- C#程序設計實訓指導書
- OpenCV實例精解
- PaaS程序設計
- JavaScript Unlocked
- INSTANT MinGW Starter
- Oracle數(shù)據(jù)庫從入門到運維實戰(zhàn)
- Building Mapping Applications with QGIS
- 機械工程師Python編程:入門、實戰(zhàn)與進階
- Expert Data Visualization
- Visual Basic程序設計上機實驗教程
- Mastering Web Application Development with AngularJS
- Scratch趣味編程:陪孩子像搭積木一樣學編程
- 快樂編程:青少年思維訓練