Here is the code to generate some sample data:
set.seed(1000)
dat <- data.frame(A = runif(5, -5, 5),
B = runif(5, -5, 5),
C = runif(5, -5, 5))
Data:
A B C
1 -1.721213 -4.3226204 -1.500625
2 2.588465 2.3871486 2.554616
3 -3.860636 0.8353505 -1.829158
4 1.907551 -2.8422860 3.658128
5 0.164024 -2.4387760 2.641607
I want to compare each column and return TRUE
either FALSE
depending on whether there is a negative or a positive value when we go down the line. For example, in row 4 of columns A and B we would get TRUE
. Because one is positive and the other is negative. If it were replaced (a negative value in for this string, but a positive value in B), it would also return TRUE
.
However, if one of the two compared values is between 1 and -1, the comparison will not happen, and it will simply return NA
. Here is what the final result for this example looks like:
A B C AB BC AC
1 -1.721213 -4.3226204 -1.500625 FALSE FALSE FALSE
2 2.588465 2.3871486 2.554616 FALSE FALSE FALSE
3 -3.860636 0.8353505 -1.829158 NA NA FALSE
4 1.907551 -2.8422860 3.658128 TRUE TRUE FALSE
5 0.164024 -2.4387760 2.641607 NA TRUE NA
, :
if((dat$A > 1 & datB < -1) | (dat$A < -1 & dat$B > -1) == TRUE)
...
, .
:
, , . mpalanco - . , DMC, - , .