官术网_书友最值得收藏!

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

主站蜘蛛池模板: 应城市| 武夷山市| 临海市| 龙里县| 乐亭县| 凤台县| 嘉黎县| 滦平县| 温泉县| 贵德县| 丹东市| 鞍山市| 肇源县| 太仓市| 明溪县| 泽库县| 石林| 大新县| 绵阳市| 彭州市| 永胜县| 崇左市| 福贡县| 磐安县| 固始县| 全南县| 巢湖市| 淳安县| 和平区| 银川市| 久治县| 台山市| 化州市| 天台县| 中卫市| 肇源县| 工布江达县| 长子县| 奉化市| 田东县| 连山|