R語言中的row()函數用於獲取矩陣的行號。
用法: row(x, as.factor=FALSE)
參數:
x:矩陣
作為因子:一個邏輯值,指示該值是否應作為列標簽的因子(如果需要創建)而不是作為數字返回
範例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
相關用法
- R語言 col()用法及代碼示例
- R語言 max.col()用法及代碼示例
- R語言 determinant()用法及代碼示例
- R語言 det()用法及代碼示例
- R語言 nrow()用法及代碼示例
- R語言 is.matrix()用法及代碼示例
- R語言 data.matrix()用法及代碼示例
- R語言 as.matrix()用法及代碼示例
- R語言 rowMeans()用法及代碼示例
- R語言 length()用法及代碼示例
- R語言 charmatch()用法及代碼示例
- R語言 class()用法及代碼示例
- R語言 typeof()用法及代碼示例
- R語言 strftime()用法及代碼示例
- R語言 density()用法及代碼示例
- R語言 sweep()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Getting a Matrix of number of rows in R Programming – row() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
