- R Data Visualization Cookbook
- Atmajitsinh Gohil
- 149字
- 2021-08-06 19:21:06
Editing a matrix in R
R allows us to edit (add, delete, or replace) elements of a matrix using the square bracket notation, as depicted in the following lines of code:
mat = matrix(c(1:10),nrow = 2, ncol = 5) mat mat[2,3]
How to do it…
In order to extract any element of a matrix, we can specify the position of that element in R using square brackets. For example, mat[2,3]
will extract the element under the second row and the third column. The first numeric value corresponds to the row and the second numeric value corresponds to a column [row, column].
Similarly, to replace an element, we can type the following lines in R:
mat[2,3] = 16
To select all the elements of the second row, we can use mat[2, ]
. If we do not specify any numeric value for a column, R will automatically assume all columns.
推薦閱讀
- Python編程自學手冊
- C++程序設計(第3版)
- Blender 3D Incredible Machines
- PhoneGap Mobile Application Development Cookbook
- SharePoint Development with the SharePoint Framework
- 微課學人工智能Python編程
- ROS機器人編程實戰
- Beginning C# 7 Hands-On:The Core Language
- Learning D3.js 5 Mapping(Second Edition)
- 一覽眾山小:ASP.NET Web開發修行實錄
- Getting Started with the Lazarus IDE
- Apache Kafka 1.0 Cookbook
- Eclipse開發(學習筆記)
- 開發者測試
- 零基礎學Python(升級版)