If you really want to insert immediately after GeneX.GT thethe corresponding GeneX.AD you can use also following approach. Should be faster than a loop.
Names <- c("cebi", "pithe", "Gene1.GT", "sapiens", "Gene2.GT", "calli", "Gene3.GT")
# Get Position of ".GT's"
id <- grep(".GT",Names)
# Create a index: old element gets rank, "AD's" gets half-rank
Seq <- c(seq_along(Names),id+0.5)
# Append AD's
Names <- append(Names,gsub("GT","AD",Names[id]))
# Order (AD's after GT's)
Names[order(Seq)]
It's a little unclear how you are mapping between names and genotypes. Can you explain a bit more about how the result relates to the input?
Thank you for your reply. I want to match the part Gene1, Gene2, Gene3... and get both GTs and ADs for them. For example, I want to match "Gene1" common in both objects and get Gene1.GT and Gene1.AD from (Genotype) and get the (Result). So, I want to match Gene1:Gene1000 and get all the corresponding GTs and ADs in the same order it matches with the (Names).