I want to obtain datetime differences in mins in an other column, in front of my datetimes. I have tried this : T1 <- c("12/31/03 23:49","1/1/04 1:14","1/1/04 0:02") T2 <- c("1/1/04 0:58","1/1/04 1:16","") toto <- data.frame(T1,T2) toto y <- strptime(T1,"%m/%d/%y %H:%M") x <- strptime(T2,"%m/%d/%y %H:%M") difftime(x,y) but, i don't know how can i do in order to obtain something like this : ans <- c(69,2,NA) res <- data.frame(T1,T2,ans) res what is to be done ? Thanks. Florent Bonneu Laboratoire de Statistique et Probabilit??s bureau 148 b??t. 1R2 Universit?? Toulouse 3 118 route de Narbonne - 31062 Toulouse cedex 9 bonneu at cict.fr
Try difftime(x,y,unit="min") or as.numeric(difftime(x,y,unit="min")) depending on what you want. On 1/11/06, bonneu at cict.fr <bonneu at cict.fr> wrote:> I want to obtain datetime differences in mins in an other column, in front of my > datetimes. I have tried this : > > T1 <- c("12/31/03 23:49","1/1/04 1:14","1/1/04 0:02") > T2 <- c("1/1/04 0:58","1/1/04 1:16","") > toto <- data.frame(T1,T2) > toto > > y <- strptime(T1,"%m/%d/%y %H:%M") > x <- strptime(T2,"%m/%d/%y %H:%M") > difftime(x,y) > > > but, i don't know how can i do in order to obtain something like this : > > ans <- c(69,2,NA) > res <- data.frame(T1,T2,ans) > res > > what is to be done ? > Thanks. > > Florent Bonneu > Laboratoire de Statistique et Probabilit??s > bureau 148 b??t. 1R2 > Universit?? Toulouse 3 > 118 route de Narbonne - 31062 Toulouse cedex 9 > bonneu at cict.fr > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Is this what you want?> toto$ans <- difftime(x,y) > totoT1 T2 ans 1 12/31/03 23:49 1/1/04 0:58 69 2 1/1/04 1:14 1/1/04 1:16 2 3 1/1/04 0:02 NA>On 1/11/06, bonneu@cict.fr <bonneu@cict.fr> wrote:> > I want to obtain datetime differences in mins in an other column, in front > of my > datetimes. I have tried this : > > T1 <- c("12/31/03 23:49","1/1/04 1:14","1/1/04 0:02") > T2 <- c("1/1/04 0:58","1/1/04 1:16","") > toto <- data.frame(T1,T2) > toto > > y <- strptime(T1,"%m/%d/%y %H:%M") > x <- strptime(T2,"%m/%d/%y %H:%M") > difftime(x,y) > > > but, i don't know how can i do in order to obtain something like this : > > ans <- c(69,2,NA) > res <- data.frame(T1,T2,ans) > res > > what is to be done ? > Thanks. > > Florent Bonneu > Laboratoire de Statistique et Probabilités > bureau 148 bât. 1R2 > Université Toulouse 3 > 118 route de Narbonne - 31062 Toulouse cedex 9 > bonneu@cict.fr > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >-- Jim Holtman Cincinnati, OH +1 513 247 0281 What the problem you are trying to solve? [[alternative HTML version deleted]]
On Wed, 11 Jan 2006 bonneu at cict.fr wrote:> I want to obtain datetime differences in mins in an other column, in front of my > datetimes. I have tried this : > > T1 <- c("12/31/03 23:49","1/1/04 1:14","1/1/04 0:02") > T2 <- c("1/1/04 0:58","1/1/04 1:16","") > toto <- data.frame(T1,T2) > toto > > y <- strptime(T1,"%m/%d/%y %H:%M") > x <- strptime(T2,"%m/%d/%y %H:%M") > difftime(x,y) > > > but, i don't know how can i do in order to obtain something like this : > > ans <- c(69,2,NA) > res <- data.frame(T1,T2,ans) > resdata.frame(T1, T2, mins=as.numeric(difftime(x,y, units="mins"))) -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595