Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k 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 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...