I want to recode NA and NaN values for rows where a column value is X. Here is my data structure.
V1 V2 V3 V4 V5
1 4 9 15 A
2 12 12 3 B
3 NaN 7 NA X
I want to replace NaN and NA values to 999 where V5 = X
V1 V2 V3 V4 V5
1 4 9 15 A
2 12 12 3 B
3 999 7 999 X
I used the code below, but it is not working
df2 <- replace_na(df$V5 == "X", 999)
Can someone help?