I have a big data frame like the example below.
df <- data.frame(IND= seq(1:20), S = LETTERS[1:20], FA=c(0,0,133,0,2,2,2,0,0,4,4,4,6,6,0,0,0,4,2,8),
MO = c(77,0,77,1,3,1,1,1,0,3,1,5,5,3,0,0,100,3,5,5)
)
I need create two new variables (SFA and SMO) when the FA and MO are equals IND . I need the below output
out<- df <- data.frame(IND= seq(1:20),
S = LETTERS[1:20],
FA=c(0,0,133,0,2,2,2,0,0,4,4,4,6,6,0,0,0,4,2,8),
MO = c(77,0,77,1,3,1,1,1,0,3,1,5,5,3,0,0,100,3,5,5),
SFA=c(0,0,133,0,"B","B","B",0,0,"D","D","D","F","F",0,0,0,"D","B","H"),
SMO=c(77,0,77,"A","C","A","A","A",0,"C","A","E","E","C",0,0,100,"C","E","E"))
I tried match the variables and after merge, but did not work very well.
THanks