I have a dataframe with duplicate IDs, but the rows are not identical. Is there a function, which identifies the column (or columns), where a difference appears?
My real application is a dataframe with hundreds of columns. I need some way to check, whether changes were made in important columns or in some irrelevant ones. So first of all I need to identify the changed columns.
Example:
ID <- c(1,2,2,4,5,5,5,6,6,7)
Info1 <- c(10,20,20,40,50,50,50,65,60,70)
Info2 <- c('A','B','A','D', 'E','E','F', 'Z','A','B')
Info3 <- c(999,998,997,995,995,995,995,946,800,805)
df <- data.frame(ID, Info1, Info2, Info3)
ID Info1 Info2 Info3
1 1 10 A 999
2 2 20 B 998
3 2 20 A 997
4 4 40 D 995
5 5 50 E 995
6 5 50 E 995
7 5 50 F 995
8 6 60 Z 946
9 6 60 A 800
10 7 70 B 805
My goal would be an additional column, which contains the changed column, i.e. desired output:
ID Info1 Info2 Info3 col_diff
1 1 10 A 999 <NA>
2 2 20 B 998 Info2; Info3
3 2 20 A 997 Info2; Info3
4 4 40 D 995 <NA>
5 5 50 H 995 Info2
6 5 50 E 995 Info2
7 5 50 F 995 Info2
8 6 65 Z 946 Info1; Info2; Info3
9 6 60 A 800 Info1; Info2; Info3
10 7 70 B 805 <NA>
I hope my problem became clear. I hope there is some function within dplyr, which I do not know yet. Of course my solution with the additional column is not really elegant. So I am open to any ideas, which may solve my problem.
Thanks a lot!