當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


R語言 nrow()用法及代碼示例

R語言中的nrow()函數用於返回指定矩陣的行數。

用法: nrow(x)
參數: 
x: matrix, vector, array or data frame 
 

範例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)

輸出:



  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

相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Get the number of rows of an Object in R Programming – nrow() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。