as.matrix()R语言中的函数用于将对象转换为矩阵。
用法: as.matrix(x)
参数:
x:要转换的对象
范例1:
# R program to convert an object to matrix
# Creating a vector
x <- c(1:9)
# Calling as.matrix() Function
as.matrix(x)输出:
[, 1]
[1, ] 1
[2, ] 2
[3, ] 3
[4, ] 4
[5, ] 5
[6, ] 6
[7, ] 7
[8, ] 8
[9, ] 9
范例2:
# R program to convert an object to matrix
# Calling pre-defined data set
BOD
# Calling as.matrix() Function
as.matrix(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
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
相关用法
- R语言 data.matrix()用法及代码示例
- R语言 as.vector()用法及代码示例
- R语言 type.convert()用法及代码示例
- R语言 is.matrix()用法及代码示例
- R语言 as.list()用法及代码示例
- R语言 as.character()用法及代码示例
- R语言 as.integer()用法及代码示例
- R语言 as.logical()用法及代码示例
- R语言 toString()用法及代码示例
- R语言 as.table()用法及代码示例
- R语言 as.factor()用法及代码示例
- R语言 as.Date()用法及代码示例
- R语言 melt()用法及代码示例
- R语言 sapply()用法及代码示例
- R语言 identity()用法及代码示例
- R语言 which()用法及代码示例
- R语言 call()用法及代码示例
- R语言 cumprod()用法及代码示例
- R语言 is.character()用法及代码示例
- R语言 ncol()用法及代码示例
- R语言 is.factor()用法及代码示例
注:本文由纯净天空筛选整理自nidhi_biet大神的英文原创作品 Convert an Object into a Matrix in R Programming – as.matrix() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
