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

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

主站蜘蛛池模板: 铁岭市| 青岛市| 竹北市| 阿拉善右旗| 陇南市| 嘉善县| 马尔康县| 正镶白旗| 奉新县| 黄平县| 安达市| 明光市| 彭泽县| 白玉县| 沧源| 巴马| 海淀区| 台南县| 区。| 八宿县| 临高县| 桂东县| 涟水县| 康平县| 石泉县| 遂溪县| 汉川市| 随州市| 灯塔市| 五台县| 容城县| 镇雄县| 新兴县| 绥宁县| 长海县| 赞皇县| 芜湖县| 荣昌县| 定兴县| 广水市| 竹山县|