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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
