Table1 <- data.frame(CName = c("aa", "bb", "cc", "dd"),
number = c("X11", "X22", "X33", "X44"))
Table2 <- data.frame(PName = c("zz", "yy", "xx", "ww"),
"X11" = c(5, 6, 3, 5),
"X22" = c(7, 5, 4, 3),
"X44" = c(9, 9, 1, 1))
I got Table1
CName number
1 aa X11
2 bb X22
3 cc X33
4 dd X44
I got Table2
PName X11 X22 X44
1 zz 5 7 9
2 yy 6 5 9
3 xx 3 4 1
4 ww 5 3 1
I want to get two files:
(1) by matching CName of Table 1 to column Heading of Table 2, I want to have a new table like this:
ResultsTable1
PName aa bb dd
1 zz 5 7 9
2 yy 6 5 9
3 xx 3 4 1
4 ww 5 3 1
I also wants to know the what is missing, i.e. In this example, cc is missing in Table2, so it is not matched.
ResultTable2
Table1:
Table2: cc
Are there any effective way of doing these?
Set the column names other than the first column of
Table2based on the values inTable1This will show what’s in
Table1[["CName"]]that’s not in the newcolnamesofTable2And this will show what’s in the new
colnamesofTable2, but not inTable1[["CName"]]Perhaps some simple examples of the
%in%syntax will help (note that this is documented in?matchand thatA %in% Bis just an alternate syntax formatch(A, B, nomatch=0) > 0For your data, I used
as.characterto convert fromfactortocharacter