I have a file contains p-values of my analysis. I want to use if else statement to do the following:
if p-value less that 0.01 give a green color. if p-value is greater than 0.01 and less that 0.05 give a red color. if p-value greater than 0.05 give a yellow color.
I tried to use the following code but is doesn't work:
col=ifelse(data < 0.01,"green" , ifelse(data > 0.01 & data < 0.05, "red"), ifelse(data>0.05, "yellow"))).
Is there a reason why you are using
instead of
else if () {}
I like structuring my code using (whitespace) indentation to have a better overview of where a block begins and ends. But this is a matter of taste, you can also put in all in one line. Unlike languages such as Python, R does not use strict indentations, so you are free to do it as you like.