difftime

Grouped mean of difftime fails in data.table

爱⌒轻易说出口 提交于 2020-08-02 08:39:15
问题 Preface: I have a column in a data.table of difftime values with units set to days. I am trying to create another data.table summarizing the values with dt2 <- dt[, .(AvgTime = mean(DiffTime)), by = Group] When printing the new data.table, I see values such as 1.925988e+00 days 1.143287e+00 days 1.453975e+01 days I would like to limit the decimal place values for this column only (i.e. not setting options() unless I can do this specifically for difftime values this way). When I try to do this

Grouped mean of difftime fails in data.table

你离开我真会死。 提交于 2020-08-02 08:36:55
问题 Preface: I have a column in a data.table of difftime values with units set to days. I am trying to create another data.table summarizing the values with dt2 <- dt[, .(AvgTime = mean(DiffTime)), by = Group] When printing the new data.table, I see values such as 1.925988e+00 days 1.143287e+00 days 1.453975e+01 days I would like to limit the decimal place values for this column only (i.e. not setting options() unless I can do this specifically for difftime values this way). When I try to do this

Grouped mean of difftime fails in data.table

为君一笑 提交于 2020-08-02 08:36:32
问题 Preface: I have a column in a data.table of difftime values with units set to days. I am trying to create another data.table summarizing the values with dt2 <- dt[, .(AvgTime = mean(DiffTime)), by = Group] When printing the new data.table, I see values such as 1.925988e+00 days 1.143287e+00 days 1.453975e+01 days I would like to limit the decimal place values for this column only (i.e. not setting options() unless I can do this specifically for difftime values this way). When I try to do this

Grouped mean of difftime fails in data.table

余生颓废 提交于 2020-08-02 08:36:29
问题 Preface: I have a column in a data.table of difftime values with units set to days. I am trying to create another data.table summarizing the values with dt2 <- dt[, .(AvgTime = mean(DiffTime)), by = Group] When printing the new data.table, I see values such as 1.925988e+00 days 1.143287e+00 days 1.453975e+01 days I would like to limit the decimal place values for this column only (i.e. not setting options() unless I can do this specifically for difftime values this way). When I try to do this

Calculate time difference (difftime) between columns of different rows

╄→尐↘猪︶ㄣ 提交于 2020-01-13 19:07:35
问题 I have data on 'Start' and 'End' time for different jobs, grouped by 'owner': Data <- data.frame( job = c(1, 2, 3, 4, 5), owner = c("name1", "name2", "name1", "name1", "name2"), Start = as.POSIXct(c("2015-01-01 15:00:00", "2015-01-01 15:01:00", "2015-01-01 15:13:00", "2015-01-01 15:20:00", "2015-01-01 15:39:02"), format="%Y-%m-%d %H:%M:%S"), End = as.POSIXct(c("2015-01-01 15:11:11", "2015-01-01 15:17:21", "2015-01-01 15:17:00", "2015-01-01 15:31:21", "2015-01-01 15:40:11"), format="%Y-%m-%d

How to get time differences with output having multiple units

泪湿孤枕 提交于 2019-12-24 05:20:09
问题 Good day, I have two date columns in as.POSIXct in the format YYYY-MM-DD HH:MM:SS. I would like to get the difference between the two, displayed in the format Days Hours:Seconds. Here is some dummy data: a<-c("2018-03-20 11:52:25 AST", "2018-03-20 12:51:25 AST", "2018-03-20 14:19:04 AST", "2018-03-21 14:12:12 AST", "2018-03-21 12:09:22 AST", "2018-03-21 15:28:01 AST") b<-c("2018-04-09 18:39:38 AST", "2018-06-23 19:13:14 AST", "2018-03-20 23:23:03 AST", "2018-05-10 21:29:28 AST", "2018-03-22

Calulcate running difference of time using difftime on one column of timestamps

若如初见. 提交于 2019-12-23 05:05:27
问题 How would you calculate time difference of two consecutive rows of timestamps in minutes and add the result to a new column. I have tried this: data$hours <- as.numeric(floor(difftime(timestamps(data), (timestamps(data)[1]), units="mins"))) But only get difference from time zero and onwards. Added example data with 'mins' column that I want to be added timestamps mins 2013-06-23 00:00:00 NA 2013-06-23 01:00:00 60 2013-06-23 02:00:00 60 2013-06-23 04:00:00 120 回答1: The code that you're using

How to make a timespan column based on a time stamp column?

大兔子大兔子 提交于 2019-12-13 15:24:17
问题 I have a datatable with timestamps in column 1 and events in column 2. The timestamps have the format Y-m-d H:M:OS3 (e.g. "2019-09-26 07:29:22,778" ). I would like to add a new column with time-span values of the difference between timestamp 2 to timestamp 1, then 3 to 1 etc. E.g.: timestamp event diff in sec 2019-09-26 07:29:22,778 X 2019-09-26 07:29:23,918 Y 1.140 2019-09-26 07:29:25,118 Z 2.340 . . 回答1: In base : dt1$timediff <- cumsum(c(0, difftime(tail(dt1$timestamp,-1), head(dt1

How to calculate number of days between two dates in one column in R

試著忘記壹切 提交于 2019-12-13 03:29:32
问题 I have the following two data frames: Date <- seq(as.Date("2013/1/1"), by = "day", length.out = 17) x <-data.frame(Date) x$discharge <- c("1000","1100","1200","1300","1400","1200","1300","1300","1200","1100","1200","1200","1100","1400","1200","1100","1400") x$discharge <- as.numeric(x$discharge) And Date2 <- c("2013-01-01","2013-01-08","2013-01-12","2013-01-17") y <- data.frame(Date2) y$concentration <- c("1.5","2.5","1.5","3.5") y$Date2 <- as.Date(y$Date2) y$concentration <- as.numeric(y

Using conditional statements with difftime in R

大兔子大兔子 提交于 2019-12-13 00:23:36
问题 The problem: (1) identify the date of the first instance of "O" and then (2) identify the first instance of of "A" after the given "O" (3) to calculate difference in time using difftime. (similar to: Time Calculation Between Specific Events) The issue specifically is with (2), identifying the first instance of "A" after the given "O". Data frame (df) with columns Date and Event looks like this: "Date" "Event" "2000-09-08" "A" "2000-09-11" "N" "2000-09-12" "O" "2000-09-13" "O" "2000-09-14" "O"