I have a dataset like this
dt <- data.table(Score = c(0.33,0.34,00.3, -0.22, 0.232),
Id2 = c("0/0","0/1","1/0","0/0","0/0"),
Kps = c("0/1","0/0","1/1","0/1","0/0"),
Inr = c("0/0","0/1","1/1","0/0","0/1"))
I need to replace the values of each row based on the Score column as like this
- If "0/0" or "1/1" then
Score * 2 - If "1/0" or "0/1" then
Score
Usually, it can be done by using the base function like this
dt$Id2 <- dt$Score * 2
But here I have to consider each row and I have around 1000 columns so it can be only done with loop
The expected output
Score Id2 Kps Inr
0.330 0.66 0.330 0.66
0.340 0.340 0.68 0.340
0.300 0.300 0.6 0.6
-0.220 -0.44 -0.22 -0.44
0.232 0.464 0.464 0.232
Any suggestions?