w1=data.frame(name=c("A","B","A","A","C"),school=c(1,2,1,1,1),class=c("10","5","4","11","1"),ENGLISH=c(85,50,90,90,12))
> w1
name school class ENGLISH
1 A 1 10 85
2 B 2 5 50
3 A 1 4 90
4 A 1 11 90
5 C 1 1 12
> w2=data.frame(name=c("A","B","C"),school=c(3,2,1),class=c("5","5","1"),MATHS =c(80,89,55), ENGLISH=c(85,50,90,90,12))
Error in data.frame(name = c("A", "B", "C"), school = c(3, 2, 1), class = c("5", :
参数值意味着不同的行数: 3, 5
> w2=data.frame(name=c("A","B","C"),school=c(3,2,1),class=c("5","5","1"),MATHS =c(80,89,55), ENGLISH=c(88,81,32))
> w2
name school class MATHS ENGLISH
1 A 3 5 80 88
2 B 2 5 89 81
3 C 1 1 55 32
> merge(w1, w2, all = T)
name school class ENGLISH MATHS
1 A 1 10 85 NA
2 A 1 11 90 NA
3 A 1 4 90 NA
4 A 3 5 88 80
5 B 2 5 50 NA
6 B 2 5 81 89
7 C 1 1 12 NA
8 C 1 1 32 55
> merge(w1, w2, by = c("NAME", "SCHOOL", "CLASS"), all = T)
Error in fix.by(by.x, x) : 'by'必需指定唯一有效的列
> merge(w1, w2, by = c("name", "school", "class"), all = T)
name school class ENGLISH.x MATHS ENGLISH.y
1 A 1 10 85 NA NA
2 A 1 11 90 NA NA
3 A 1 4 90 NA NA
4 A 3 5 NA 80 88
5 B 2 5 50 89 81
6 C 1 1 12 55 32
c("NAME", "SCHOOL", "CLASS")改为c("name", "school", "class"), all = T)
网友评论