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

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

主站蜘蛛池模板: 道孚县| 靖州| 沧州市| 获嘉县| 内江市| 江门市| 姜堰市| 酒泉市| 鹤壁市| 平乡县| 嘉禾县| 黑龙江省| 米林县| 安庆市| 防城港市| 澳门| 饶河县| 织金县| 祁连县| 广灵县| 南阳市| 黎川县| 惠东县| 固安县| 壤塘县| 黎川县| 房产| 宝丰县| 新野县| 吉木乃县| 广昌县| 绥德县| 合肥市| 镇雄县| 诏安县| 思茅市| 哈尔滨市| 阜宁县| 北流市| 雅安市| 简阳市|