I have the following dataframes
df1:
round mun1 mun2
1 SP PA
1 RJ PR
1 BH BA
2 BA SP
2 PR BH
2 PA RJ
3 RJ BH
3 PA PR
3 SP BA
df2:
mun p01 p02 p03
SP 3 4 7
RJ 0 3 4
BH 3 6 9
BA 0 1 1
PA 1 2 3
PR 1 4 5
I need a column in df1, P, that equals 0 if round==1, maxvalue of p01 if round ==2 and the maxvalue of p02 if round==3.
In the real data, in df1 i have 38 rounds, and 380 lines, and in df2 i have 20 lines (each for unique mun). I tried the following loop:
p <-matrix(0, nrow=380,ncol=1)
for(i in 2:38){
p <- if(round==i) max(p[[i-1]] %in% df2)
}
But this doesn't work. Is there a way to do that?