When I dplyr::filter
a data.frame
with labels, the labels remain but not for variables of class difftime
:
library(tidyverse)
library(sjlabelled)
df <- data.frame(a = c(1, 2, 3),
start = c("2009-10-16",
"2009-08-13",
"2008-02-01"),
end = c("2009-12-17",
"2009-12-13",
"2008-08-03"))
df$start <- as.Date(df$start, format = "%Y-%m-%d")
df$end <- as.Date(df$end, format = "%Y-%m-%d")
df <- df %>%
mutate(days_diff = end - start) %>%
sjlabelled::var_labels(
a = "cat variable",
start = "start date",
end = "end date",
days_diff = "day difference")
df
when we filter:
df2 <- df %>%
filter(a == 1)
the label is removed:
I thought this shouldn't happen anymore, see here and here. Is this a bug or am I missing something?
Thanks