I have the following data frame:
A P(A)
1 0.8
0 0.7
1 0.5
1 0.8
1 0.9
0 0.7
0 0.8
For all 0's in column A
, I would like to calculate 1-P(A)
. This would give me the following dataset:
A P(A)
1 0.8
0 0.3 ## 1 - 0.7
1 0.5
1 0.8
1 0.9
0 0.3 ## 1 - 0.7
0 0.2 ## 1 - 0.8
I tried this but it doesn't give me the required output.
for(i in nrow(results)) {
if(results[i,1]==0) {
results[i,2]<- 1-results[i,2]
}
}
How is this possible in R?