I'm dealing with a large dataset and I'm trying to call which row satisfies a condition in both columns. However, I want to exclude certain values from the analysis and I figured setting them as "NA"s would be the best. To complicate this, in case of "NA"s in one of the column, I still want to see if the other column with numerical value still satisfies a condition. Below is an example of my dataset.
col1 = as.numeric(c(10, 2, 15, 2, "NA", 15))
col2 = as.numeric(c(15, 15, 2, 2, 15, "NA"))
test <- data.frame(col1, col2)
Let's say my cutoff is 5, so I want the following result:
col1 col2 G5
1 10 15 Yes
2 2 15 No
3 15 2 No
4 2 2 No
5 NA 15 Yes
6 15 NA Yes
I tried the following but rows 5 and 6 come back as "NA" and I don't know how to address this.
test$G5 <- ifelse(test$col1 > 5 & test$col2 > 5, "Yes", "No")
col1 col2 G5
1 10 15 Yes
2 2 15 No
3 15 2 No
4 2 2 No
5 NA 15 <NA>
6 15 NA <NA>
What is the best way of setting up ifelse statement so that "NA" can be taken as "False"?. I think problem is that when ifesle considers either column and logical test is performed with "NA", it can only return "NA".
This is first time I'm posting this so my formatting maybe very bad... sorry about that!
Thank you