posixct

converting datetime string to POSIXct date/time format in R

跟風遠走 提交于 2019-11-26 16:42:45
问题 Consider a string in the format test <- "YYYY-MM-DDT00:00:00.000-08:00" My goal is to convert those strings to POSIXct format so that I can plot the data. my initial thought was to use as.POSIXct(test) ...but that seems to truncate the datetime to just date. Any thoughts? The help info for as.POSIXct seems to imply that the input should be date and time separated by a space, not by a "T". Is this my issue? 回答1: You need to specify a format for your conversion. Take a read of ?strptime to see

Accurately converting from character->POSIXct->character with sub millisecond datetimes

末鹿安然 提交于 2019-11-26 16:37:56
问题 I have a character datetime column in a file. I load the file (into a data.table ) and do things that require the column to be converted to POSIXct . I then need to write the POSIXct value back to file, but the datetime will not be the same (because it is printed incorrectly). This print/formatting issue is well known and has been discussed several times. I've read some posts describing this issue. The most authoritative answers I found are given in response to this question. The answers to

How to calculate time difference with previous row of a data.frame by group

自闭症网瘾萝莉.ら 提交于 2019-11-26 14:07:32
问题 The problem I am trying to solve is that I have a data frame with a sorted POSIXct variable in it. Each row is categorized and I want to get the time differences between each row for each level and add that data back into a new variable. The reproducible problem is as below. The below function is just for creating sample data with random times for the purpose of this question. random.time <- function(N, start, end) { st <- as.POSIXct(start) en <- as.POSIXct(end) dt <- as.numeric(difftime(en,

How R formats POSIXct with fractional seconds

狂风中的少年 提交于 2019-11-26 01:15:33
问题 I believe that R incorrectly formats POSIXct types with fractional seconds. I submitted this via R-bugs as an enhancement request and got brushed off with \"we think the current behavior is correct -- bug deleted.\" While I am very appreciative of the work they have done and continue to do, I wanted to get other peoples\' take on this particular issue, and perhaps advice on how to make the point more effectively. Here is an example: > tt <- as.POSIXct(\'2011-10-11 07:49:36.3\') > strftime(tt,