merge函数的声明:
merge(x, y, by = intersect(names(x), names(y)),
by.x = by, by.y = by, all = FALSE, all.x = all, all.y = all,
sort = TRUE, suffixes = c(".x",".y"),
incomparables = NULL, ...)
merge函数参数的说明:
x,y:用于合并的两个数据框
by,by.x,by.y:指定依据哪些行合并数据框,默认值为相同列名的列.
all,all.x,all.y:指定x和y的行是否应该全在输出文件.
sort:by指定的列是否要排序.
suffixes:指定除by外相同列名的后缀.
incomparables:指定by中哪些单元不进行合并.
例子:
w1:
NAME SCHOOL CLASS ENGLISH
A S1 10 85
B S2 5 50
A S1 4 90
A S1 11 90
C S1 1 12
w2:
NAME SCHOOL CLASS MATHS ENGLISH
A S3 5 80 88
B S2 5 89 81
C S1 1 55 32
按照NAME, SCHOOL, CLASS合并w1和w2:
merge(w1, w2, all = T)