# Getting a Matrix of number of rows in R Programming – row() Function

** row()** function in R Language is used to get the row number of a matrix.

Syntax:row(x, as.factor=FALSE)

Parameters:x:matrixas.factor:a logical value indicating whether the value should be returned as a factor of column labels (created if necessary) rather than as numbers

**Example 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)` |

**Output:**

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

**Example 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)` |

**Output:**

[, 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