所以最近我学会了使用months_between和readline()
如何使用readline()来使用month_between?
我想知道用户从雇佣日期开始工作了多少天(雇用人员从前线读取())到现在为止当天+雇用日期的哪一天
离) “你在周三被录用,工作到现在为止283天”
我现在尝试的例子是这样的
find_day <- function(){
response <- readline(prompt='When were you hired?(XXXX-XX-XX)')
x <- Sys.Date()-as.Date(response)
y <- format(response,'%A')
print(x)
print(y)
}
我知道有很多错误但只是想知道如何解决它
答案 0 :(得分:0)
lubridate
包会在这里为您提供帮助。以下是执行计算的一种方法:
response <- readline(prompt='When were you hired? (XXXX-XX-XX)(year-mon-day)')
response <- ymd(response)
day_of_week <- wday(response, label=TRUE, abbr=FALSE)
time_since_hire <- as.period(interval(response,now()), unit="days")
paste0("You were hired on ",day_of_week," and worked for ",day(time_since_hire)," days until now.")
示例输出:
[1]“你在星期六被录用了777天,直到现在。”
(FYI months_between
通常是Oracle或类似的SQL函数。)