I am trying to add a new column result
in my dataframe df1
, as specific columns (value1
and value2
columns) met the following conditions:
Both of them row-wisely are positive, negative or 0, or one of them is 0 and another is either negative or positive, then
result=="True"
;if row-wisely one of them are positive and another is negative or verse versa, then
result=="False"
;if row-wisely both of them are
NA
s or one of them isNA
but another is either negative or positive, thenresult=="-"
Input:
df1 <- data.frame(ID= c("ID1","ID2","ID3","ID4","ID5"), value1 = c(1.2, -1, NA, -1.5, 0), value2 = c(0.8, -1.1, -1, 1.3, 0.9))
Expected output:
df2 <- data.frame(ID= c("ID1","ID2","ID3","ID4","ID5"), value1 = c(1.2, -1, NA, -1.5, 0), value2 = c(0.8, -1.1, -1, 1.3, 0.9), result = c("True","True","-", "False", 'True'))
Out:
Any helps would be appreciated.
Reference link: