[R] lubridate inserting unwelcome 9:21

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Tue Mar 28 20:38:26 CEST 2017


Analyzing time data as POSIXct without dates is IMO unwise (likely to give you trouble). My approach is to always keep the date and time together or to use numeric hours-after-midnight. Others have invented packages like chron to deal with such data.
-- 
Sent from my phone. Please excuse my brevity.

On March 28, 2017 8:28:30 AM PDT, Troels Ring <tring at gvdnet.dk> wrote:
>Dear friends - I have a series of times on successive days and would 
>like to convert them into a successive common time for each person (ID)
>
>. Using lubridate and adding days(1) does as expected apart from 
>changing time zone to LMT from UTC and suddenly adding 9:21 (H:M) to
>all 
>times. Individual parts of the instructions seem OK. I'm sorry for the 
>clumsy demonstration - but the error comes through.
>
>R version 3.3.2 (2016-10-31) - Windows.
>
>All best wishes
>Troels
>
>library(lubridate)
>
>SSS <- structure(list(ID = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
>1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
>3L, 3L, 3L, 3L, 3L, 3L), Time = c(-1L, 0L, 1L, 2L, 3L, 4L, 5L,
>6L, 7L, 8L, 9L, 10L, 11L, -1L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
>8L, 9L, 10L, -1L, 0L, 1L, 2L, 3L, 4L, 5L), VT = structure(c(3L,
>5L, 11L, 11L, 8L, 10L, 8L, 10L, 8L, 7L, 11L, 5L, 5L, 12L, 5L,
>7L, 7L, 5L, 5L, 8L, 10L, 8L, 7L, 7L, 7L, 2L, 8L, 7L, 8L, 7L,
>10L, 8L), .Label = c("02:00", "03:00", "04:00", "05:00", "06:00",
>"09:00", "10:00", "11:00", "11:30", "12:00", "13:00", "14:00",
>"15:00", "17:00", "18:00", "21:30", "23:00"), class = "factor")),
>.Names 
>= c("ID",
>"Time", "VT"), row.names = c(NA, 32L), class = "data.frame")
>
>SSS$VT  <- parse_date_time(SSS$VT,"HM")
>str(SSS$VT)
>
>TT <- list()
>for(i in 1:3) {
>#i <- 1
>BS <- subset(SSS,ID==i)
>TT[[i]] <- c(BS$VT + (1:length(BS[,1])-1)*days(1))
>}
>BS$VT
>(1:length(BS[,1])-1)*days(1)
>
>#these appear as expected but
>
>TT
>
>#appears disturbed 9:21 inserted - LMT time zone - how comes?
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.



More information about the R-help mailing list