R语言 按行组合矢量、矩阵或数据框 – rbind()函数
R语言中的 rbind() 函数用于按行组合指定的向量、矩阵或数据框。
语法: rbind(x1, x2, …, deparse.level = 1)
参数:
x1, x2: 矢量、矩阵、数据框
deparse.level: 这个值决定了列名的生成方式。deparse.level的默认值是1。
例1 :
# R program to illustrate
# rbind function
# Initializing two vectors
x <- 2:7
y <- c(2, 5)
# Calling rbind() function
rbind(x, y)
输出
[, 1] [, 2] [, 3] [, 4] [, 5] [, 6]
x 2 3 4 5 6 7
y 2 5 2 5 2 5
例2 :
# R program to illustrate
# rbind function
# Initializing a vector
x <- 1:5
# Calling rbind() function
rbind(x, 4)
rbind(x, 5, deparse.level = 0)
rbind(x, 6, deparse.level = 2)
rbind(x, 4, deparse.level = 6)
输出
[, 1] [, 2] [, 3] [, 4] [, 5]
x 1 2 3 4 5
4 4 4 4 4
[, 1] [, 2] [, 3] [, 4] [, 5]
[1, ] 1 2 3 4 5
[2, ] 5 5 5 5 5
[, 1] [, 2] [, 3] [, 4] [, 5]
x 1 2 3 4 5
6 6 6 6 6 6
[, 1] [, 2] [, 3] [, 4] [, 5]
[1, ] 1 2 3 4 5
[2, ] 4 4 4 4 4