Questions tagged [difftime]

A function in R that calculates the difference of two times.

A function in that calculates the difference of two times.

is a function in that provides creation, printing and some arithmetic for calculating time intervals or time differences.

The signature of is as follows:

difftime(time1, time2, tz, units = c("auto", "secs", "mins", "hours", "days", "weeks"))

See official documentation for more details.

181 questions
2
votes
1 answer

Error "Origin must be supplied" when using difftime + subtraction operator not working for different minutes

I have a data frame of two columns "start" and "end" in HH:MM:SS format. I wanted to calculate duration between start and end using difftime function It always gives back this error: Error in as.POSIXct.numeric(time1) : 'origin' must be supplied I…
Acer acer
  • 23
  • 4
2
votes
1 answer

How to use a shifting function in postgres to determine time difference by row?

I am looking to use some sort of shift function in postgresql to figure out time difference by row. Below i have a table of workers with start and stop times for each of two companies. I can do this very easily in R. Here is my data set print out…
LoF10
  • 1,907
  • 1
  • 23
  • 64
2
votes
0 answers

format - display fractional time data as hh:mm:ss R

I have data below for work hours which I need to compare - start and stop with date and time. I first extract the time portion of each as start and stop variables, then use the chron package to change them from factor data to something I can compare…
Adam_S
  • 687
  • 2
  • 12
  • 24
2
votes
1 answer

Turn dataframe of dates into time difference symm matrix in R

I have a dataframe of letters and dates: Dates <- data.frame(X = c("A", "B", "C", "D"), Y = c("1/1/1988","1/1/2000","11/1/1996", "2/1/1990")) Dates$Y <- as.Date(Dates$Y, "%m/%d/%Y") I'm trying to turn this data frame into a symmetrical matrix where…
2
votes
1 answer

Error in as.POSIXct.default(time1)

I get the above error when trying to find an interval between two days. x <- as.POSIXct(strptime(as.character(wo_data$In.Progress.time),"%m/%d/%Y %I:%M:%S %p")) class(x) # [1] "POSIXct" "POSIXt" wo_data$super.schedule.inprogress…
eliran
  • 21
  • 1
  • 2
2
votes
1 answer

R as.difftime() issue for times longer than 1 day

I need to convert time intervals in the format %H:%M:%S (class = factor) to class = difftime. I am currently using as.difftime() to do this, but it returns NA when the hour value is > 23. TimeElapsed_raw = as.factor(c("03:59:59", "21:00:00",…
pradlee
  • 23
  • 3
2
votes
1 answer

Converting Time datatype to character string in R language

When selecting the 'Time' column from the dataframe, I get the time in "%H:%M:%S" format > tail(sf_arrest[,c("Time")],1) # A tibble: 1 × 1 Time
2
votes
1 answer

How to calculate difference in time between variable rows in R?

I am looking to calculate differences in time for different groups based on beginning work times and end work times. How can I tell R to calculate difftime between two rows based on their labels couched in a group? Below is a sample data…
LoF10
  • 1,907
  • 1
  • 23
  • 64
2
votes
1 answer

Is there a faster alternative to difftime function in R?

I have a time series dataset with around 120,000 rows, which I am storing as a data frame. Most of the data is at 15 minute interval, but there is some monthly data also. I want to keep only the 15 minute data and eliminate the data at monthly…
code_is_entropy
  • 611
  • 3
  • 11
2
votes
2 answers

Average number of seconds between two time observations

I have a irregular time index from an xts object. I need to find the average number of seconds between two time observations. This is the my sample data: dput(tt) structure(c(1371.25, NA, 1373.95, NA, NA, 1373, NA, 1373.95, 1373.9, NA, NA, 1374,…
runjumpfly
  • 319
  • 1
  • 10
2
votes
1 answer

difftime in R dataframe based on subset

I've got this sample dataframe, that keeps track of the time when a lamp is switched on and off. time lamp status 1 2015-01-01 12:18:17 2 ON 2 2015-01-01 13:07:29 28 ON 3 2015-01-01 13:11:50 28 OFF 4 …
Wimpel
  • 26,031
  • 1
  • 20
  • 37
2
votes
2 answers

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

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…
2
votes
3 answers

Calculate time difference (difftime) between columns of different rows

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…
tobias_
  • 468
  • 5
  • 21
2
votes
3 answers

Why is difftime Only Returning Whole Numbers?

For some reason difftime is only returning whole numbers. My code is pretty simple. #include int main() { time_t test = time(NULL); while (1) { std::cout << difftime(time(NULL), test) << std::endl; } } My output…
DeepDeadpool
  • 1,441
  • 12
  • 36
2
votes
2 answers

difftime() adds decimal numbers

I am trying to get the number of days from a specific date using difftime(). If I use the November date (10.11.14) it works fine, if I use the September date (10.09.14) it adds .0417 to the date. Any idea how I can solve this? head(dummydat) reihe…
conva
  • 33
  • 4
1 2
3
12 13