Gregg
2020-Jun-23 05:13 UTC
[R] How to convert column from millisecond epoch time to yyyy-mm-dd GMT
Hello to all the smart people out there.... I have a data.frame labeled itsm_service_type_field. I need to convert the Timestamp field which is epoch time in milliseconds to a yyyy-mm-dd GMT Date.? Data.frame format is below. I've attempted to use the lapply and as.POSIXct functions to convert the time field in the original data.frame to a new data.frame I've labeled "itsm_service_type_field_adjusted_time", but I've got the order and syntax wrong. Help would be so much appreciated. Thanks in advance. Gregg Arizona Details - See Below: itsm_service_type_field <- fread("itsm_service_type_2018-2019_CONUS.csv")>>>>>>>>>>>>>???????????itsm_service_type_field_adjusted_time <- lapply(itsm_service_type_field[ , Timestamp], as.POSIXct(Timestamp, origin="1970-01-01", tz="GMT"))head(itsm_service_type_field) ? ? Id? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Timestamp? ? ? ? ?Data Type Visibility? ? ? ? ? ? ? ? ? ? ? TYPE_SERVICE 1: INCBR0005072277 1577059200000 itsm-ticket U&FOUO&USA??????????? 0 2: INCBR0005073034 1577059200000 itsm-ticket U&FOUO&USA??????????? 1 3: INCBR0005073131 1577059200000 itsm-ticket U&FOUO&USA??????????? 0 4: INCBR0005074186 1577059200000 itsm-ticket U&FOUO&USA??????????? 0 5: INCBR0005074188 1577059200000 itsm-ticket U&FOUO&USA??????????? 0 6: INCBR0005074546 1577059200000 itsm-ticket U&FOUO&USA??????????? 0 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 477 bytes Desc: OpenPGP digital signature URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20200623/b4584a9c/attachment.sig>
Enrico Schumann
2020-Jun-23 19:09 UTC
[R] How to convert column from millisecond epoch time to yyyy-mm-dd GMT
On Tue, 23 Jun 2020, Gregg via R-help writes:> Hello to all the smart people out there.... > > I have a data.frame labeled itsm_service_type_field. I need to convert > the Timestamp field which is epoch time in milliseconds to a > yyyy-mm-dd GMT Date.? > > Data.frame format is below. > > I've attempted to use the lapply and as.POSIXct > functions to convert the time field in the original > data.frame to a new data.frame I've labeled > "itsm_service_type_field_adjusted_time", > but I've got the order and syntax wrong. > > Help would be so much appreciated. > > Thanks in advance. > Gregg > Arizona > > Details - See Below: > > itsm_service_type_field <- fread("itsm_service_type_2018-2019_CONUS.csv") > >>>>>>>>>>>>>>???????????itsm_service_type_field_adjusted_time <- lapply(itsm_service_type_field[ , Timestamp], as.POSIXct(Timestamp, origin="1970-01-01", tz="GMT")) > > head(itsm_service_type_field) > ? ? Id? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Timestamp? ? ? ? ?Data Type Visibility? ? ? ? ? ? ? ? ? ? ? TYPE_SERVICE > 1: INCBR0005072277 1577059200000 itsm-ticket U&FOUO&USA??????????? 0 > 2: INCBR0005073034 1577059200000 itsm-ticket U&FOUO&USA??????????? 1 > 3: INCBR0005073131 1577059200000 itsm-ticket U&FOUO&USA??????????? 0 > 4: INCBR0005074186 1577059200000 itsm-ticket U&FOUO&USA??????????? 0 > 5: INCBR0005074188 1577059200000 itsm-ticket U&FOUO&USA??????????? 0 > 6: INCBR0005074546 1577059200000 itsm-ticket U&FOUO&USA??????????? 0 >You should divide by 1000: .POSIXct(1577059200000/1000, tz = "GMT") ## [1] "2019-12-23 GMT" as.POSIXct(1577059200000/1000, origin = as.POSIXct("1970-01-01 00:00:00", tz = "GMT"), tz = "GMT") ## [1] "2019-12-23 GMT" -- Enrico Schumann Lucerne, Switzerland http://enricoschumann.net
William Dunlap
2020-Jun-23 19:20 UTC
[R] How to convert column from millisecond epoch time to yyyy-mm-dd GMT
When you give an example it really helps to (a) show the data as the output of dput() or dump() so one can copy and paste into R and (b) show the result (the wrong value or error message) that you got. You example is missing some quotes and has an unneeded call to lapply().> dump("Data", file=stdout())Data <- structure(list(Id = c("INCBR0005072277", "INCBR0005073034", "INCBR0005073131", "INCBR0005074186", "INCBR0005074188"), Timestamp = c(1577059200000, 1577059200000, 1577059200000, 1577059200000, 1577059200000), `Data Type` = c("itsm-ticket", "itsm-ticket", "itsm-ticket", "itsm-ticket", "itsm-ticket"), Visibility = c("U&FOUO&USA", "U&FOUO&USA", "U&FOUO&USA", "U&FOUO&USA", "U&FOUO&USA"), TYPE_SERVER = c(0L, 1L, 0L, 0L, 0L)), row.names = c(NA, -5L ), class = "data.frame")> str(as.POSIXct(Data$Timestamp/1000,origin=as.POSIXct("1970-01-01",tz="UTC"), tz="UTC")) POSIXct[1:5], format: "2019-12-23" "2019-12-23" "2019-12-23" "2019-12-23" "2019-12-23" Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Jun 23, 2020 at 11:24 AM Gregg via R-help <r-help at r-project.org> wrote:> Hello to all the smart people out there.... > > I have a data.frame labeled itsm_service_type_field. I need to convert the > Timestamp field which is epoch time in milliseconds to a yyyy-mm-dd GMT > Date. > > Data.frame format is below. > > I've attempted to use the lapply and as.POSIXct functions to convert the > time field in the original data.frame to a new data.frame I've labeled > "itsm_service_type_field_adjusted_time", > but I've got the order and syntax wrong. > > Help would be so much appreciated. > > Thanks in advance. > Gregg > Arizona > > Details - See Below: > > itsm_service_type_field <- fread("itsm_service_type_2018-2019_CONUS.csv") > > >>>>>>>>>>>>>???????????itsm_service_type_field_adjusted_time <- > lapply(itsm_service_type_field[ , Timestamp], as.POSIXct(Timestamp, > origin="1970-01-01", tz="GMT")) > > head(itsm_service_type_field) > Id Timestamp Data Type > Visibility TYPE_SERVICE > 1: INCBR0005072277 1577059200000 itsm-ticket U&FOUO&USA 0 > 2: INCBR0005073034 1577059200000 itsm-ticket U&FOUO&USA 1 > 3: INCBR0005073131 1577059200000 itsm-ticket U&FOUO&USA 0 > 4: INCBR0005074186 1577059200000 itsm-ticket U&FOUO&USA 0 > 5: INCBR0005074188 1577059200000 itsm-ticket U&FOUO&USA 0 > 6: INCBR0005074546 1577059200000 itsm-ticket U&FOUO&USA > 0______________________________________________ > 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. >[[alternative HTML version deleted]]