Re: Converting numerics to date format
Huzefa Khalil <[email protected]> Wed, 10 Jun 2026 15:53:10 -0400
| Newsgroups | gmane.comp.lang.r.general |
|---|---|
| Message-ID | <CADsG8gM_Bkj-TryEiaKreB8z2YH2ZPG+j5v7cAiHe6uPaU+OAw@mail.gmail.com> |
Perhaps something like this? as.POSIXct(SUBSUB$PKDOSDTC_PM_RAW, format =3D "%d-%b-%Y %H:%M") + 12 * 60 *= 60 On Wed, Jun 10, 2026 at 3:24=E2=80=AFPM Dennis Fisher <[email protected]= > wrote: > > R 4.6.2 > OS X > > Colleagues, > > I am having a problem with conversion of a numeric to date format. In th= e example shown below, the first column is the original date value. > > The second column is the conversion to numeric. > > In the third column, I add 0.5 to the second column. > > The fourth column converts the third column back to a date format using t= he following code: > FORMAT <- "%d-%b-%Y %H:%M" > SECPERDAY <- 24 * 60 * 60 > SUBSUB <- structure(list(PKDOSDTC_PM_RAW =3D c("06-Apr-2025 10:30", "10-D= ec-2025 07:15", "11-May-2025 07:30", "16-Mar-2025 08:00", "11-May-2025 08:= 00", "16-Mar-2025 08:00", "22-Sep-2024 09:00", "11-Aug-2025 09:00", "20-O= ct-2024 08:00", "14-Jan-2026 10:00", "03-Nov-2025 08:00" > ), PM.ELAPSED =3D c(20184.438, 20432.302, 20219.312, 20163.333, 20219.33= 3, 20163.333, 19988.375, 20311.375, 20016.333, 20467.417, 20395.333), FIX.= PM.ELAPSED =3D c(20184.938, 20432.802, 20219.812, 20163.833, 20219.833, 20= 163.833, 19988.875, 20311.875, 20016.833, 20467.917, 20395.833), FIX.PM.RA= W =3D c("06-Apr-2025 15:30", "10-Dec-2025 11:15", "11-May-2025 12:30", "16= -Mar-2025 13:00", "11-May-2025 13:00", "16-Mar-2025 13:00", "22-Sep-2024 1= 4:00", "11-Aug-2025 14:00", "20-Oct-2024 13:00", "14-Jan-2026 14:00", "03-= Nov-2025 12:00" > )), row.names =3D c(36L, 71L, 120L, 183L, 253L, 288L, 316L, 400L, 414L, = 505L, 519L), class =3D "data.frame") > SUBSUB$REVISED <- format.Date(SUBSUB$nREVISED * SECPERDA= Y, format=3DFORMAT) > > Note the following: > 1. nREVISED is 0.5 larger than nORIGINAL, i.e., 12 hours > 2. the difference between REVISED and ORIGINAL is either 4 or 5 = hours -- I intended it to be 12 hours. > > The discrepancy of 8 or 7 hours (12 - [4 or 5]) suggests to me that the p= roblem involves time times; the occurrence of 4 vs. 5 is presumably due to = daylight savings time (PST vs. PDT). > > I suspect that the problem can be solved by adding TZ to the code and pos= sibly origin. But various attempts to do this all fail. > > Any suggestions? > > Dennis > > Dennis Fisher MD > P < (The "P Less Than" Company) > Phone: 415 307-4791 > www.PLessThan.com > > ORIGINAL nORIGINAL nREVISED REVISED > 36 06-Apr-2025 10:30 20184.44 20184.94 06-Apr-2025 15:30 > 71 10-Dec-2025 07:15 20432.30 20432.80 10-Dec-2025 11:15 > 120 11-May-2025 07:30 20219.31 20219.81 11-May-2025 12:30 > 183 16-Mar-2025 08:00 20163.33 20163.83 16-Mar-2025 13:00 > 253 11-May-2025 08:00 20219.33 20219.83 11-May-2025 13:00 > 288 16-Mar-2025 08:00 20163.33 20163.83 16-Mar-2025 13:00 > 316 22-Sep-2024 09:00 19988.38 19988.88 22-Sep-2024 14:00 > 400 11-Aug-2025 09:00 20311.38 20311.88 11-Aug-2025 14:00 > 414 20-Oct-2024 08:00 20016.33 20016.83 20-Oct-2024 13:00 > 505 14-Jan-2026 10:00 20467.42 20467.92 14-Jan-2026 14:00 > 519 03-Nov-2025 08:00 20395.33 20395.83 03-Nov-2025 12:00 > ______________________________________________ > [email protected] mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide https://www.R-project.org/posting-guide.= html > and provide commented, minimal, self-contained, reproducible code.