ID <- c("A","B","C","D","E")
AT <- c(0.1,0.2,0.3,0.4,0.5)
US <- c(NA,NA,0.6,NA,NA)
FIGX <- c(1,NA,NA,2,3)
W1 <- c(NA,10,20,30,40)
test.Data <- data.frame(ID,AT,US,FIGX,W1) %>% as.data.table()
I have this kind of table. I would like to replace the values of column US by values of FIGX if NA, and if FIGX is NA, then to replace by the W1 column values.
I have tried this
test.Data %>% mutate_if(is.na(US),mutate_if(is.na(FIGX),W1))
without success.
How should I do?