I have a dataframe looks like:
df <- read.table(text="chr pos Ref Alt D045313 D045314 D045135 D045136 D045137 D045138
Chr1 1462191 T C 1/1 0/1 1/1 0/0 1/1 1/1
Chr1 1463534 G C 0/0 1/1 0/0 0/1 0/0 0/0
Chr1 1463881 T A 0/1 0/0 1/1 0/0 1/1 1/1
Chr1 1464091 G A 0/0 0/0 1/1 0/0 1/1 1/1
Chr1 1464651 T C 1/1 0/0 1/1 0/1 1/1 1/1",head=F, stringsAsFactors=F)
The expected result:
chr pos Ref Alt D045313 D045314 D045135 D045136 D045137 D045138
Chr1 1462191 T C C/C T/C C/C T/T C/C C/C
Chr1 1463534 G C G/G C/C G/G G/C G/G G/G
Chr1 1463881 T A T/A T/T A/A T/T A/A A/A
Chr1 1464091 G A G/G G/G A/A G/G A/A A/A
Chr1 1464651 T C C/C T/T C/C T/C C/C C/C
the replacements would follow this: in df[5:10], "0" should be replaced by the character in df$Ref, "1" by the character in df$Alt. I checked the question in this link[Replace specific characters in a variable in data frame in R, but it didn't work on my situation. Appreciate any helps.