I have a data frame that looks like the following:
index A B correct
1 1 1 -
2 1 2 -
3 1 3 0
4 2 1 -
5 2 2 -
6 2 3 1
I would like to propagate the value of 'correct' to other rows when A matches. I.e. the desired output:
index A B correct
1 1 1 0
2 1 2 0
3 1 3 0
4 2 1 1
5 2 2 1
6 2 3 1
So all the rows that has A = 1 will have the same value of correct, which is propagated from row(A=1,B=3).
How should I do this in R? I have a big dataframe with many columns and it is seems that using loops to manipulate dataframes is not recommended in R. Any help would be greatly appreciated!