If you are going use 'numeric' date values further in numeric
calculations sometimes it is advisable to convert to numeric
> x1 <- as.POSIXct(c('2011-08-11 12:00', '2011-08-14 15:15'))
> difftime(x1[2], x1[1], units = 'days')
Time difference of 3.135417 days
> as.numeric(difftime(x1[2], x1[1], u
You were using difftime incorrectly; look at the help page.
> x1 <- as.POSIXct(c('2011-08-11 12:00', '2011-08-14 15:15'))
> x1
[1] "2011-08-11 12:00:00 EDT" "2011-08-14 15:15:00 EDT"
> ceiling(difftime(x1[2], x1[1], units = 'days'))
Time difference of 4 days
>
On Sun, Aug 14, 2011 at 9:33 AM, Ji
Use Date instead of POSIXct. Since your data is already POSIXct you need to
convert to character and then Date before you use difftime.
> a <- as.POSIXct("2011-08-02 00:01:00")
> b <- as.POSIXct("2011-08-01 23:59:00")
>
as.Date(as.character(a,format="%Y-%m-%d"))-as.Date(as.character(b,format="%
3 matches
Mail list logo