I am trying to add a new column "result" in my dataframe df1, if the condition is
- select only specific columns (from count1:count3 columns) have negative value, then result = "negative"
- if any one of the columns (count1, count2, count3) have a positive value the result = "positive"
input
df1<- data.frame(ID= c("ID1","ID2","ID3","ID4"), count1 = c(1,-1,0,-1), count2 = c(1,-1,-1,1), count3 = c(1,-1,1,-1))
expected output
df2 <- data.frame(ID= c("ID1","ID2","ID3","ID4"),count1 = c(1,-1,1,-1), count2 = c(1,-1,-1,1), count3 = c(1,-1,1,-1), result = c("positive","negative","positive","positive"))
ID count1 count2 count3 result
ID1 1 1 1 positive
ID2 -1 -1 -1 negative
ID3 1 -1 1 positive
ID4 -1 1 -1 positive