0
start <- as.POSIXct("2016-01-17")  
end <- start + as.difftime(72, units="days")  
for(i in seq(from=start, by=60*60*24*7, to=end)) {  
       print(i)  
}

As the codes show above, I try to print out the date after Year 2016 within 72 days. However, the output is always numbers such as 1453006800. I've tried everything I can think of including as.Date, as.Date(i, origin="2016-01-17 00:00:00 EST")....Thanks!

user5843090
  • 127
  • 1
  • 7

1 Answers1

0

The problem here is that while "start" and "end" are POSIX date objects, "i" is not. This is evident by checking their structures:

> str(start)
 POSIXct[1:1], format: "2016-01-17"
> str(i)
 num 1.46e+09

You can use other looping function instead of "for", which seem to be coercing "i" to numeric. You can use a while loop like:

> i = start
> while (i < end) {
 i = i + 60*60*24*7
 print(i)
}
andrechalom
  • 737
  • 3
  • 13