compare datasets

Hi all!
I have several data sets that I want to compare with each other (df0 with df1, df1 with df2 and df2 with df3). When a change is made, a variable identifying the source of the change should be entered for each column in a new column.

Here are my sample data sets:

df0 = data.frame("ind" = c("A1", "A2", "B1", "C1", "C2"), "x10" = c(0,NA,2,3,4), "x11" = c(NA,0,1,2,3), "x12" = c(3,4,0,NA,NA))
df1 = data.frame("ind" = c("A1", "A2", "B1", "C1", "C2"), "x10" = c(0,NA,1,3,3), "x11" = c(NA,0,1,3,3), "x12" = c(3,2,0,NA,NA))
df2 = data.frame("ind" = c("A1", "A2", "B1", "C1", "C2", "D1"), "x10" = c(0,NA,1,3,3,NA), "x11" = c(NA,0,1,3,3,NA), "x12" = c(3,2,0,NA,NA,NA))
df3 = data.frame("ind" = c("A1", "A2", "B1", "C1", "C2", "D1"), "x10" = c(0,1,1,3,3,NA), "x11" = c(4,0,1,3,3,1), "x12" = c(3,2,0,2,1,NA), "x13" = c(0,1,NA,2,1,1))

The result for the comparison of df0 and df1 should look like (x means, that there was some change):

In the next step, df1 would be compared with df2. If there are changes, the variable y should be written into the change_x1.-column, which would have the following result:


The final comparison of df2 with df3 would lead to the following result (z indicates a change between the two data sets):

Do you have any idea, how I could solve that problem in R?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.