I have a dataframe df like below
V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | score | Name | ID |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 5 | AA | 1 |
1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 5 | AA | 2 |
0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | CC | 3 |
0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | CC | 4 |
0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 10 | EE | 5 |
0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 10 | EE | 6 |
0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 15 | GG | 7 |
0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 15 | GG | 8 |
0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 5 | HH | 9 |
0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 5 | HH | 10 |
0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | KK | 11 |
0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | KK | 12 |
i need to multiple the values from column 'V1' to column 'score' by -1 to change them to negative. i was thinking of using if(df$ID%%2==0) condition
the output should look like this
V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | score | Name | ID |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 5 | AA | 1 |
-1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | -5 | AA | 2 |
0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | CC | 3 |
0 | -1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | CC | 4 |
0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 10 | EE | 5 |
0 | 0 | -1 | 0 | 0 | 0 | 0 | 0 | 0 | -10 | EE | 6 |
0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 15 | GG | 7 |
0 | 0 | 0 | -1 | 0 | 0 | 0 | 0 | 0 | -15 | GG | 8 |
0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 5 | HH | 9 |
0 | 0 | 0 | 0 | -1 | 0 | 0 | 0 | 0 | -5 | HH | 10 |
0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | KK | 11 |
0 | 0 | 0 | 0 | 0 | -1 | 0 | 0 | 0 | 0 | KK | 12 |
Any suggestions on how to do this effectively?