R 語言中的 col() 函數用於獲取一個矩陣,該矩陣包含作為參數傳遞給它的矩陣的列數。
用法: col(x, as.factor=FALSE)
參數:
x:矩陣
作為因子:一個邏輯值,指示該值是否應作為列標簽的因子(如果需要創建)而不是作為數字返回
範例1:
# R program to illustrate
# col 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 col() function
col(x)輸出:
     [, 1] [, 2]
[1, ]    1    3
[2, ]    2    4
     [, 1] [, 2]
[1, ]    1    2
[2, ]    1    2
範例2:
# R program to illustrate
# col function
  
# Initializing a matrix with
# 3 rows and 3 columns
x <- matrix(rep(1:9), 3, 3)
  
# Getting the matrix representation
x
  
# Calling the col() function
col(x)輸出:
     [, 1] [, 2] [, 3]
[1, ]    1    4    7
[2, ]    2    5    8
[3, ]    3    6    9
     [, 1] [, 2] [, 3]
[1, ]    1    2    3
[2, ]    1    2    3
[3, ]    1    2    3
相關用法
- R語言 max.col()用法及代碼示例
- R語言 colSums()用法及代碼示例
- R語言 scale()用法及代碼示例
- R語言 row()用法及代碼示例
- R語言 determinant()用法及代碼示例
- R語言 det()用法及代碼示例
- R語言 ncol()用法及代碼示例
- R語言 merge()用法及代碼示例
- R語言 rename()用法及代碼示例
- R語言 select()用法及代碼示例
- R語言 is.matrix()用法及代碼示例
- R語言 data.matrix()用法及代碼示例
- R語言 as.matrix()用法及代碼示例
- R語言 length()用法及代碼示例
- R語言 charmatch()用法及代碼示例
- R語言 class()用法及代碼示例
- R語言 typeof()用法及代碼示例
- R語言 strftime()用法及代碼示例
- R語言 density()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Getting a Matrix of number of columns in R Programming – col() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
