Here is one approach. I used the package stringibecause it does a great job with pattern vectors and line vectors for searching.
, , :
short <- ifelse(nchar(df$Alt) > nchar(df$REF), df$REF, df$Alt)
long <- ifelse(nchar(df$REF) > nchar(df$Alt), df$REF, df$Alt)
, . , , , :
library(stringi)
df[,!(names(df) %in% c("REF", "Alt"))] <-
lapply(1:(ncol(df) - 2),
function(ii) stri_replace_all_fixed(df[ ,ii + 2], long, "I"))
df[,!(names(df) %in% c("REF", "Alt"))] <-
lapply(1:(ncol(df) - 2),
function(ii) stri_replace_all_fixed(df[ ,ii + 2], short, "D"))