[R] time difference

Dirk Eddelbuettel edd at debian.org
Wed Jul 22 17:52:14 CEST 2009


On 22 July 2009 at 09:44, Erin Hodgess wrote:
| I am looking at the ctime attribute of two different files.  It
| contains the year, month, day, time of creation and time zone.

[ Well only if you convert it to POSIXlt... ]

| Is there a way to determine the difference between the ctimes of two
| files, please?

Just use '-' or the difftime() functions. As help(file.info) clearly states, the
class of the ctime component is a standard POSIXct and your problem reduces
to the common difference between two POSIXct times.  Which R happens to excel at:

> bashrc <- file.info("~/.bashrc")$ctime
> Rprofile <- file.info("~/.Rprofile")$ctime
> Rprofile - bashrc
Time difference of 52.57426 days
> difftime(Rprofile, bashrc, units="weeks")
Time difference of 7.510608 weeks

See ?difftime for other units, and use as.numeric() to cast to just a number.

Hth, Dirk 

-- 
Three out of two people have difficulties with fractions.




More information about the R-help mailing list