I have two columns
V1 V2
T 1
A 0
C 0
If the column V2 is 1, then I want to replace nucleotide complementary if 0 is left as is I wrote a for function (in my many rows of data), but after his performance I get
V1 V2 V3
T 1 NA
A 0 NA
C 1 G
I use code
for(i in nrow(Tri1_a)){
if(Tri1_a$V2[i] == 1){
if(Tri1_a$V1[i] == "T")
Tri1_a$V3[i] = "A"
if(Tri1_a$V1[i] == "A")
Tri1_a$V3[i] = "T"
if(Tri1_a$V1[i] == "G")
Tri1_a$V3[i] = "C"
if(Tri1_a$V1[i] == "C")
Tri1_a$V3[i] = "G"
}
else{
Tri1_a$V3[i] = Tri1_a$V1[i]
}
i = i + 1
}
but i want get
V1 V2 V3
T 1 A
A 0 A
C 1 G
where is the mistake?
whether it is possible to do it without the for, for examle using apply?