I am trying to locate the nearest Sunday to today.
I define today as:
dt <- as.Date("2014-06-04")
I can find the last Sunday by following:
dt - as.POSIXlt(dt)$wday
[1] "2014-06-01"
I can find the next Sunday by following:
dt + as.POSIXlt(dt)$wday
[1] "2014-06-07"
Not sure why the following is not working:
ifelse(as.POSIXlt(dt)$wday <= 3,
dt - as.POSIXlt(dt)$wday,
dt + as.POSIXlt(dt)$wday)
[1] 16222
I am getting a number: 16222
instead of a date.
Each of the following statements work as expected:
as.POSIXlt(dt)$wday
class(as.POSIXlt(dt)$wday)
as.POSIXlt(dt)$wday <= 3
Any ideas??