📜  在 R 编程中获取行数矩阵 - row()函数

📅  最后修改于: 2022-05-13 01:55:47.629000             🧑  作者: Mango

在 R 编程中获取行数矩阵 - row()函数

R语言中的row()函数用于获取矩阵的行号。

示例 1:

# R program to illustrate
# row function
  
# Initializing a matrix with
# 2 rows and 2 columns
x <- matrix(c(1, 2, 3, 4), 2, 2)
  
# Getting the matrix representation
x
  
# Calling the row() function
row(x)

输出:

$Rscript main.r
     [, 1] [, 2]
[1, ]    1    3
[2, ]    2    4

     [, 1] [, 2]
[1, ]    1    1
[2, ]    2    2

示例 2:

# R program to illustrate
# row function
  
# Initializing a matrix with
# 3 rows and 3 columns
x <- matrix(rep(1:12), 3, 3)
  
# Getting the matrix representation
x
  
# Calling the row() function
row(x)

输出:

[, 1] [, 2] [, 3]
[1, ]    1    4    7
[2, ]    2    5    8
[3, ]    3    6    9

     [, 1] [, 2] [, 3]
[1, ]    1    1    1
[2, ]    2    2    2
[3, ]    3    3    3