An R package for Chronological objects which can handle dates and times, written by David James.
Questions tagged [chron]
111 questions
6
votes
4 answers
How to convert date to the closest weekend (Saturday)
I have a data frame with Date in the "%d-%m-%Y" format and have the week number. The dates are weekdays and I want the the Saturday for that week in another column.
I had initially check whether the date is a weekday or weekend using function in the…

Ami
- 197
- 1
- 12
6
votes
2 answers
ggplot2 and chron barplot of time data scale_x_chron
I have a number of times and want to plot the frequency of each time in a barplot
library(ggplot2)
library(chron)
test <- data.frame(times = c(rep("7:00:00",4), rep("8:00:00",3),
rep("12:00:00",1),…

schlusie
- 1,907
- 2
- 20
- 26
4
votes
4 answers
datetime object to minutes: I need 3 packages
I am wondering if I am missing something?!
I would like to know: is there a better/shorter way to get minutes from a datetime object:
Lessons studied so far:
Extract time (HMS) from lubridate date time object?
converting from hms to hour:minute in…

TarJae
- 72,363
- 6
- 19
- 66
4
votes
2 answers
standard deviation of time in a column in hr:min:sec format
In the question "average time in a column in hr:min:sec format" the following example is given:
Col_Time = c('03:08:20','03:11:30','03:22:18','03:27:39')
library(chron)
mean(times(Col_Time))
[1] 03:17:27
How can I get hr:min:sec as result for the…

Chris
- 327
- 3
- 11
3
votes
1 answer
R chron times() function won't work
I'm trying to convert a time to seconds since midnight. I'm having a hard time getting the times() function from the chron package to work. Here's how I'm using it:
> library(chron)
> 24 * 24 * 60 * (times(50))
Error in 24 * 24 * 60 * (times(50))…

screechOwl
- 27,310
- 61
- 158
- 267
3
votes
3 answers
Create array of start/end of day datetimes in R
I'm using R to do some time series analysis using zoo and chron. I've got a zoo object with lots of data in it, and need to be able to use the window function to subset the data to just one days worth, then the next days worth, then the next…

robintw
- 27,571
- 51
- 138
- 205
3
votes
0 answers
PM2 Stops app at unexpected times with SIGINT "process killed" and the reason is not clear
The app stops and I can't figure out why.
I start the command like this CMD ["pm2-runtime", "main.bundle.js", "--cron", "0 */16 * * *"] (should mean to restar the app every 16 hours)
Then I see the app starting:
15:35:02
2020-01-09T15:35:02: PM2…

07mm8
- 2,702
- 2
- 8
- 20
3
votes
3 answers
Why is the chron package treating 2 digit years oddly starting from 2030?
I recently noticed an odd behavior in R I can't explain. I had this in some old code:
The following should produce the list of months from 01/1980 -> 01/2029 and it works as expected:
length(chron::seq.dates("01/31/80", "01/03/29", by="months"))
[1]…

Denis
- 11,796
- 16
- 88
- 150
3
votes
3 answers
Sequence of only time (no dates) in r
I am trying to make a sequence that only consists of times with one hour interval, without dates. It should look like this:
"00:00:00" "1:00:00" "2:00:00" "3:00:00"
I know that this code works:
dat <- seq(
from=as.POSIXct("00:00:00","%H:%M:%S",…

Sanne
- 33
- 6
3
votes
2 answers
R: Cut datetimes by time of day
I have a data_frame with POSIXct date-times. I would now like to create a variable that cuts these date-times into timebands: 1 -- [00:00:00, 08:00:00), 2 -- [08:00:00, 17:00:00), 3 -- [17:00:00, 18:30:00), 4 -- [18:30:00, 00:00:00).
Here is some…

tchakravarty
- 10,736
- 12
- 72
- 116
3
votes
1 answer
plot chron times as hours from origin
I have a set of chron times that is the difference between two time points. These values range from slightly negative to slightly greater than 1. Chron displays these values as a fraction of days because some of the values are greater than 1.
When…

user2813915
- 59
- 1
- 5
3
votes
1 answer
Using OAuth 2.0 with google apps scripts to access Instagram API
I am trying to set up a chron job to connect to the instagram API, grab 'my feed' and download the images. I cannot get past the OAuth 2.0 step. I have already looked at a number of resources including:
How to authorize with oauth 2.0 from…

aduss
- 556
- 3
- 12
3
votes
2 answers
melt with chron
I'm trying to melt a data frame with chron class
library(chron)
x = data.frame(Index = as.chron(c(15657.00,15657.17)), Var1 = c(1,2), Var2 = c(9,8))
x
Index Var1 Var2
1 (11/13/12 00:00:00) 1 9
2 (11/13/12 04:04:48) 2 8
y…

fRed
- 75
- 1
- 7
2
votes
1 answer
Preserving times Class with sqldf
I am using sqldf to join several tables, but I am having trouble preserving the times class set with the chron package on a column. I used the method="name__class" argument to the sqldf function and appropriately named my column with the class, but…

StatsStudent
- 1,384
- 2
- 10
- 28
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