R语言中的数据合并函数(merge,cbind和rbind)的使用—R语言中用cbind() 和rbind() 构建分块矩阵
1.merge函数
两个数据框拥有相同的时间或观测值,但这些列却不尽相同。处理的办法就是使用
merge(x, y ,by.x = ,by.y = ,all = ) 函数。
#merge/合并
ID
name
score
student1
student2
total_student1
total_student1
当我们需要将相同的观测对象得出的不同类型变量合并时,则采用cbind,也就是合并columm。
2.cbind函数/横向追加
ID
name
score
sex
student1
student2
total_student2
total_student2
当我们需要将不同的观测对象,相同的观测变量合并时,则采用rbind,也就是合并row。
3.rbind函数/纵向追加
ID
name
student1
ID
name
student2
total_student3
total_student3
R语言中用cbind() 和rbind() 构建分块矩阵
用cbind() 和rbind() 构建分块矩阵
正如前面所暗示的,可以利用函数cbind() 和rbind() 把向量和矩阵拼成一个