itt*_*ill 0 r lubridate dplyr
您好,我想找到 R 中日期列的最近月末。
有什么有效的方法可以做到这一点吗?
dt<-data.frame(orig_dt=as.Date(c("1997-04-01", "1997-06-29" ))) dt<-dt %>% mutate(modified_dt="Nearest_month_end_date")
即 1997-04-01 应更改为 1997-03-31,1997-06-29 应更改为 1997-06-30。
pha*_*man 6
尝试这个:
library(lubridate) dt<-dt %>% mutate(modified_dt=round_date(orig_dt, unit="month")-days(1)) #Output > dt orig_dt modified_dt 1 1997-04-01 1997-03-31 2 1997-06-29 1997-06-30
归档时间:
7 年,1 月 前
查看次数:
246 次
最近记录: