Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.5k views
in Technique[技术] by (71.8m points)

r - Why am I having trouble filtering by date and time using lubridate?

I have a data frame, and I'm trying to keep records after 10:05 AM on 1/22/21.

df1$`Date/Time Opened` <- as_datetime(df1$`Date/Time Opened`)

df2 <- df1 %>% filter("Date/Time Opened" > as_datetime("2021-01-22 10:05:00"))

It throws this error when I try to filter:

Error: Problem with `filter()` input `..1`.
x character string is not in a standard unambiguous format
i Input `..1` is `"Date/Time Opened" > as_datetime("2021-01-22 10:05:00")`.

If I use as.numeric(as_datetime("2021-01-22 10:05:00")) or as.character(as_datetime("2021-01-22 10:05:00")) it runs without throwing an error, but the filter is not applied correctly. (Either all or none of the records are filtered out.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Can you post a minimal working example? Try the reprex package to help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...