posixct

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

谁都会走 提交于 2019-11-27 14:13:06
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 that question provide two functions ( myformat.POSIXct and form ) that are supposed to solve this issue

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

会有一股神秘感。 提交于 2019-11-27 08:39:43
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, st, unit="sec")) ev <- sort(runif(N, 0, dt)) rt <- st + ev return(rt) } The code for simulating the

Aggregate values of 15 minute steps to values of hourly steps

℡╲_俬逩灬. 提交于 2019-11-27 04:44:26
问题 I have a data frame that looks like this: Timedate TotalSolar_MW 20 2013-06-01 04:45:00 13.0 21 2013-06-01 05:00:00 41.7 22 2013-06-01 05:15:00 81.8 23 2013-06-01 05:30:00 153.0 24 2013-06-01 05:45:00 270.7 25 2013-06-01 06:00:00 429.3 26 2013-06-01 06:15:00 535.4 "Timedate" is POSIXlt , and "Total_Solar" is numeric . The time steps are in 15 minute intervals from June 1, 0:00 to June 24, 24:00. Now I want to aggregate the quarter hourly data to hourly steps e.g. 2013-06-01 06:00:00 934.8MW

R - converting date and time fields to POSIXct with HHMMSS format

一曲冷凌霜 提交于 2019-11-27 02:16:22
问题 I have a data file which has three columns thus: 20010101 000000 0.833 20010101 000500 0.814 20010101 001000 0.794 20010101 001500 0.772 ... As is fairly clear to human eyes, the first two are date and time. I need to convert them into a POSIXct (or something else if it's better, but my limited past experience of dealing with timestamps in R is to use POSIXct). Normally, having pulled it in with read.table, I would use: df$DateTime <- as.POSIXct(paste(df$Date, df$Time), format="%Y%m%d %H%M%S"

How can I keep midnight (00:00h) using strptime() in R?

时间秒杀一切 提交于 2019-11-26 23:26:24
问题 I have a dataframe, df, which has factor variable for date in the following format: 2015-12-15 10:00:00 2015-12-19 12:00:00 2015-12-20 20:00:00 It is hourly data. The problem arises when looking at midnight, 00:00:00, because it doesn't appear the hour. It just says: 21/12/2015 So as you see, it only says the day but it lacks the hour. So I use strptime to convert to a date format using: df$date <- strptime(df$date,"%d/%m/%Y %H:%M") It all works fine for all the hours and days except for any

Converting numeric time to datetime POSIXct format in R

守給你的承諾、 提交于 2019-11-26 21:56:51
问题 I have a data frame containing what should be a datetime column that has been read into R. The time values are appearing as numeric time as seen in the below data example. I would like to convert these into datetime POSIXct or POSIXlt format, so that date and time can be viewed. tdat <- c(974424L, 974430L, 974436L, 974442L, 974448L, 974454L, 974460L, 974466L, 974472L, 974478L, 974484L, 974490L, 974496L, 974502L, 974508L, 974514L, 974520L, 974526L, 974532L,974538L) 974424 should equate to 00

Convert Factor to Date/Time in R

不问归期 提交于 2019-11-26 20:56:12
问题 This is the information contained within my dataframe: ## minuteofday: factor w/ 89501 levels "2013-06-01 08:07:00",... ## dDdt: num 7.8564 2.318 ... ## minutes: POSIXlt, format: NA NA NA I need to convert the minute of day column to a date/time format: minuteave$minutes <- as.POSIXlt(as.character(minuteave$minuteofday), format="%m/%d/%Y %H:%M:%S") I've tried as.POSIXlt , as.POSIXct and as.Date . None of which worked. Does anyone have ANY thoughts. The goal is to plot minutes vs. dDdt, but it

Character POSIXct Conversion in R causes wrong timezone values on daylight saving time transition (CEST/CET))

北城以北 提交于 2019-11-26 20:24:41
问题 I have a problem converting POSIXct to character and back in POSIXct in R. I run the following code: time_seq_01 <- seq(as.POSIXct("2012-10-28 02:00:00"), by = 900, length.out = 10) time_seq_02 <- as.character(time_seq_01) time_seq_03 <- as.POSIXct(time_seq_02) or equivalent: time_seq_01 <- seq(as.POSIXct("2012-10-28 02:00:00"), by = 900, length.out = 10) time_seq_02 <- format(time_seq_01,usetz = TRUE) time_seq_03 <- as.POSIXct(time_seq_02) This are the timestamps in 2012 when the daylight

Remove seconds from time in R

戏子无情 提交于 2019-11-26 17:16:45
问题 I am trying to remove the seconds from a column of hours in POSIXct format: #"2016-04-02 10:33:45 COT" "2016-04-02 22:19:24 COT" #"2016-04-09 17:47:13 COT" "2016-04-13 16:56:23 COT" x <- structure(c(1459589625, 1459631964, 1460220433, 1460562983), class = c("POSIXct", "POSIXt"), tzone = "") I am trying this but I am not seeing results: y <- as.POSIXct(x, format = "%d/%m/%Y %H:%M") 回答1: No you are giving as.POSIXct a wrong format... What about using format datetimes = as.POSIXct(c("2016-04-02

How to make time difference in same units when subtracting POSIXct

穿精又带淫゛_ 提交于 2019-11-26 16:51:37
问题 I want to subtract to POSIXct. I can do this but depending on the first row (i guess?) the difference will be in seconds or minutes. Below you can see the first diff is in seconds and the second diff is in minutes because I changed the time difference in the first row: #diff in seconds because 1st row time diff is small? t1<- as.POSIXct(c("2015-02-02 20:18:03 00:00:00", "2015-02-02 20:17:02 00:00:00"),"GMT") t2<- as.POSIXct(c("2015-02-02 20:18:02 00:00:00","2015-02-02 20:18:02 00:00:00"),"GMT