R中计算距离下一个生日的天数的函数
伙计们有人可以帮我完成这项任务吗?我正在尝试在 R 中编写一个函数,其中它需要“字符”中的出生日期并计算距下一个生日还有多少天。我不断收到同样的错误
aftellen <- function(n) {
if(class(n) == "character" | class(n) == "date") {
day_birth <- as.Date(n)
today <- Sys.Date() + 1
totaldays <- length(seq(from = today, to = day_birth, by = "days"))
print(totaldays)
} else {
print("Geef een geldige geboortedatum in")
}
}
aftellen("2022-11-03")
the error:
Error in seq.int(0, to0 - from, by) : wrong sign in 'by' argument
Guys could someone help me finish this task. I'm trying to write a function in R where it takes a date of birth in "character" and calculates how many days it is until the next birthday. I keep getting the same error
aftellen <- function(n) {
if(class(n) == "character" | class(n) == "date") {
day_birth <- as.Date(n)
today <- Sys.Date() + 1
totaldays <- length(seq(from = today, to = day_birth, by = "days"))
print(totaldays)
} else {
print("Geef een geldige geboortedatum in")
}
}
aftellen("2022-11-03")
the error:
Error in seq.int(0, to0 - from, by) : wrong sign in 'by' argument
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论