Reputation: 1
person_died_at <- c(22)
person_date_died <- c("2015-05-10")
I need to say that the person died on his birthday and calculate birthdate, using converting to Date, POSIXlt.
Upvotes: 0
Views: 160
Reputation: 1402
person_died <- as.POSIXlt("2015-05-10")
names(unclass(as.POSIXlt("2015-05-10")))
[1] "sec" "min" "hour" "mday" "mon" "year" "wday" "yday"
"isdst" "zone" "gmtoff"
a$year <- a$year - 22
person_birthdate <- a
person_birthdate
"1993-05-10 CDT"
Upvotes: 2
Reputation: 389175
Using as.POSIXlt
person_died_at <- 22
person_date_died <- "2015-05-10"
temp <- as.POSIXlt(person_date_died, tz = "UTC")
temp$year <- temp$year - person_died_at
temp
#[1] "1993-05-10 UTC"
Upvotes: 1