R语言中,cbind和rbind区别
来源:互联网 发布:seo网络推广专员 编辑:程序博客网 时间:2024/06/01 09:30
cbind: 根据列进行合并,即叠加所有列,m列的矩阵与n列的矩阵cbind()最后变成m+n列,合并前提:cbind(a, c)中矩阵a、c的行数必需相符
rbind: 根据行进行合并,就是行的叠加,m行的矩阵与n行的矩阵rbind()最后变成m+n行,合并前提:rbind(a, c)中矩阵a、c的列数必需相符
> a <- matrix(1:12, 3, 4)> print(a) [,1] [,2] [,3] [,4][1,] 1 4 7 10[2,] 2 5 8 11[3,] 3 6 9 12> > b <- matrix(-1:-12, 3, 4)> print(b) [,1] [,2] [,3] [,4][1,] -1 -4 -7 -10[2,] -2 -5 -8 -11[3,] -3 -6 -9 -12> > x=cbind(a,b)> print(x) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8][1,] 1 4 7 10 -1 -4 -7 -10[2,] 2 5 8 11 -2 -5 -8 -11[3,] 3 6 9 12 -3 -6 -9 -12> > y=rbind(a,b)> print(y) [,1] [,2] [,3] [,4][1,] 1 4 7 10[2,] 2 5 8 11[3,] 3 6 9 12[4,] -1 -4 -7 -10[5,] -2 -5 -8 -11[6,] -3 -6 -9 -12> > > c <- matrix(-1:-20, 4, 5)> print(c) [,1] [,2] [,3] [,4] [,5][1,] -1 -5 -9 -13 -17[2,] -2 -6 -10 -14 -18[3,] -3 -7 -11 -15 -19[4,] -4 -8 -12 -16 -20> > x2=cbind(a,c)Error in cbind(a, c) : 矩阵的行数必需相符(见arg2)> print(x2) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9][1,] 1 4 7 10 -1 -4 -7 -10 -13[2,] 2 5 8 11 -2 -5 -8 -11 -14[3,] 3 6 9 12 -3 -6 -9 -12 -15> > y2=rbind(a,c)Error in rbind(a, c) : 矩阵的列数必需相符(见arg2)> print(y2)Error in print(y2) : 找不到对象'y2'>
0 0
- R语言中,cbind和rbind区别
- [R]R语言中用cbind() 和rbind() 构建分块矩阵
- R语言-merge和rbind
- cbind&rbind
- 关于R语言中的merge和cbind功能的用法
- R语言学习笔记 - 1 subset和rbind实现分组求平均
- R语言数据的排序和合并--ordered();rbind()
- R table()&cbind() Fuction
- R语言中library()和require()的区别
- R语言中帮助和R包
- R tutorial 13 - cbind 黏合
- R语言中 mode(),typeof() 的区别
- C语言\r\n和\n区别
- C语言\r\n和\n区别?
- C语言\r\n和\n区别
- R语言[]和[[]]操作的区别
- C语言\r\n和\n区别
- C语言\r\n和\n区别
- spark.mllib源码阅读-聚类算法1-KMeans
- HTML标签使用
- Gitlab Omnibus
- Syrotek Course -ROS_CPP
- 简述时间复杂度和空间复杂度
- R语言中,cbind和rbind区别
- ABAP通过OLEDB读取本地Access(MDB)文件
- 欢迎使用CSDN-markdown编辑器
- ubuntu16.04 swoole 安装
- Universal Link(iOS)踩坑
- csu1779——错误的算法(模拟)
- thrift使用(2):代码生成和接口调用
- Oracle 时间修改
- 关于 MPAndroidChart 中的 LineChart 的使用小结