📜  R编程中获取对象的行数——nrow()函数

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

R编程中获取对象的行数——nrow()函数

R语言中的nrow()函数用于返回指定矩阵的行数。

示例 1:

Python3
# R program to illustrate
# nrow function
 
# Getting R Biochemical Oxygen Demand Dataset
BOD
 
# Calling nrow() function to
# get the number of rows
nrow(BOD)


Python3
# R program to illustrate
# nrow function
 
# Specifying a matrix
x <- matrix(c(1, 2, 3, 4), 1, 4)
 
# Calling the nrow() function
nrow(x)


输出:

Time demand
1    1    8.3
2    2   10.3
3    3   19.0
4    4   16.0
5    5   15.6
6    7   19.8

[1] 6

示例 2:

Python3

# R program to illustrate
# nrow function
 
# Specifying a matrix
x <- matrix(c(1, 2, 3, 4), 1, 4)
 
# Calling the nrow() function
nrow(x)

输出:

[1] 1