Hi, I have a vetor os dates with day and hour:minutes.> time1 <- c("03/08/08-11:00","03/08/08-11:10") > time1 <- as.Date(time1,"%d/%m/%y-%R") > summary(time1)Min. 1st Qu. Median Mean 3rd Qu. Max. "2008-08-03" "2008-08-03" "2008-08-03" "2008-08-03" "2008-08-03" "2008-08-03"> time1[2]-time1[1]Time difference of 0 days I need to get the difference between these minutes, my expected result in this operation is 10 minutes. How I make this in R? Thanks Ronaldo [[alternative HTML version deleted]]
You can use chron:
library(chron)
time1 <- c("03/08/08-11:00","03/08/08-11:10")
diff(as.chron(time1, "%d/%m/%y-%H:%M"))
Also you can use POSIXct but in that case be careful
about time zones. See R News 4/1.
On Mon, Nov 10, 2008 at 7:38 AM, Ronaldo Reis-Jr. <chrysopa at gmail.com>
wrote:> Hi,
>
> I have a vetor os dates with day and hour:minutes.
>
>> time1 <- c("03/08/08-11:00","03/08/08-11:10")
>> time1 <- as.Date(time1,"%d/%m/%y-%R")
>> summary(time1)
> Min. 1st Qu. Median Mean 3rd Qu.
> Max.
> "2008-08-03" "2008-08-03" "2008-08-03"
"2008-08-03" "2008-08-03"
> "2008-08-03"
>> time1[2]-time1[1]
> Time difference of 0 days
>
> I need to get the difference between these minutes, my expected result in
> this operation is 10 minutes.
>
> How I make this in R?
>
> Thanks
> Ronaldo
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
Try this: diff(strptime(time1, "%d/%m/%y-%H:%M")) On Mon, Nov 10, 2008 at 10:38 AM, Ronaldo Reis-Jr. <chrysopa@gmail.com>wrote:> Hi, > > I have a vetor os dates with day and hour:minutes. > > > time1 <- c("03/08/08-11:00","03/08/08-11:10") > > time1 <- as.Date(time1,"%d/%m/%y-%R") > > summary(time1) > Min. 1st Qu. Median Mean 3rd Qu. > Max. > "2008-08-03" "2008-08-03" "2008-08-03" "2008-08-03" "2008-08-03" > "2008-08-03" > > time1[2]-time1[1] > Time difference of 0 days > > I need to get the difference between these minutes, my expected result in > this operation is 10 minutes. > > How I make this in R? > > Thanks > Ronaldo > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]