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

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

主站蜘蛛池模板: 罗江县| 奉化市| 仲巴县| 铁岭市| 崇文区| 五指山市| 丹巴县| 分宜县| 丰台区| 揭西县| 宁蒗| 肃北| 岳阳市| 桦南县| 巴马| 宁波市| 新竹县| 太和县| 凌云县| 山阳县| 吕梁市| 吴江市| 奉贤区| 驻马店市| 湄潭县| 浏阳市| 米林县| 吐鲁番市| 任丘市| 富阳市| 通榆县| 河北省| 措美县| 攀枝花市| 巴南区| 修水县| 定襄县| 平乡县| 花莲市| 墨玉县| 海门市|