1 year ago
#389132
AlenArmjwz
Function to calculate days until next birthday in R
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
r
function
error-handling
runtime-error
cumulative-sum
0 Answers
Your Answer