0

I have a dataset (liver) where rows are patients and one column is how many days the patient waited between referral and assessment (referral_assessment_time).

I would like to filter the number of days patients waited between referral and assessment to greater than or equal to 0 days, but I keep losing the NAs despite trying some versions of rm.na = FALSE. I'd be very grateful for your help with how to keep the NAs.

liver <- liver %>% filter(referral_assessment_time >=0)

I think the question is different from "How to filter data without losing NA rows using dplyr" as that question seemed to be about strings and mine is about numbers and I can't apply that answer to my question. I'd be very grateful if @akrun reply could please be added back on here, many thanks!

s_greene
  • 3
  • 3

1 Answers1

2

An alternative would be to coalesce it:

data.frame(a=c(1, NA, 5)) %>%
  filter(coalesce(a, Inf) > 3)
#    a
# 1 NA
# 2  5
r2evans
  • 141,215
  • 6
  • 77
  • 149
  • FYI, @akrun's answer was simpler, mine is only an alternative, not sure if their answer was deleted because the question was closed or not, I see no need to have deleted it. – r2evans Feb 09 '23 at 20:54