I established a connection to an internal Teradata DB.In order to let you know my issue i have provided an exampled below.
What I am trying to do is to filter columns by my_date and narrow it down by my_key.
But I would like to keep the missing results but somehow the filter drops them within my my_result. Again currently the below code drops them if not available. As mentioned within the comments @zx8754 I have tried to add is.na(my_date)
to the filter but without success. I have also tried is.empty
, is.null
, complete
instead of collect
.
Any help would be much appreciated.
Reproducible test
# Create my_df
my_key <- c(1, 2, 3,4)
my_date <- as.Date(c('2018-07-01','2018-08-01','2018-09-01','2018-09-01'))
my_df <- data.frame(my_date, my_key)
# Filter_mydf
my_result <- my_df %>%
select (my_date,my_key)%>%
filter(between(my_date ,as.Date("2018-08-01"),as.Date("2018-09-01")),
my_key %in% c(1,2,3))%>%
collect()
my_result
my_date my_key
2018-08-01 2
2018-09-01 3
Desired my_result
my_date my_key
NA 1
2018-08-01 2
2018-09-01 3
Set my_date to NA if date is not between dates, then filter on my_key: