I have a data file with multiple columns and hundreds of rows similar to this demo table:
0.91304348 0.08333333 0.25000000 1.00000000 1.00000000 0.85714286 0.08333333 0.43478261 0.12500000 1.00000000 1.00000000 1.00000000 0.16666667 1.00000000 1.00000000
I would like to look through all values and replace any value that is greater than 0.5 by subtracting 0.5 from the value and replacing it with the resultant value. So for example if the value is 0.85714286, I'd replace that value with 0.35714286 (i.e 0.85714286 - 0.5). But a value that is <=0.5 should be left as is.
By this, the above demo table would look like this;
0.41304348 0.08333333 0.25000000 0.50000000 0.50000000 0.55714286 0.08333333 0.43478261 0.12500000 0.50000000 0.50000000 0.50000000 0.16666667 0.50000000 0.50000000
I am trying to execute a for loop in R but so far unsuccessful (being a beginner)
New_Table <-c()
for (i in 1:nrowTable) {
if (i > 0.5) {
New_Table <- (i - 0.5)
} else {
New_Table <- Table[i]
}
}
Please advise, I appreciate any help in R (or other possible approaches for learning purpose)
Thank you!