2,640 questions
2
votes
1
answer
107
views
R Default lubridate date time printing and parsing fails to read midnight
I'm working with date-time (POSIXct) observations. My workflow involves reading CSVs, manipulating the date-time data, and exporting as CSV for later use.
I've found that without tediously specifying ...
0
votes
0
answers
85
views
How to change hms(hour,minute & seconds) columns of char datatype to separate columns of hour, minute and seconds? [duplicate]
I have a column by name Time of character datatype and want to separate each hour,minute and seconds into different column.Please suggest me methods.
EX:
Time
12:29:38
18:01:39
08:56:...
1
vote
1
answer
86
views
Estimate time spent in each cycle occurence of a factor variable [closed]
Temperature is meaesured in each two minutes and temperatures between 2.0 and 7.9 are fine, 8.0 and above are hot, 0.0 and 1.9 are cold, and minus zero is too cold. I want to measure time in each ...
2
votes
3
answers
185
views
Finding the next month with year [duplicate]
I am trying to calculate the next month in YYYY MMM (e.g. 2025 Jul) format using year and month as inputs. What I have is this:
text <- "Current year is 2025"
mon <- "06"
...
1
vote
1
answer
74
views
Converting time zones from UTC to local time using tidyverse
I am trying to use tidyverse to convert a POSIXct object with a time zone of UTC to an alternative known time zone. I've tried different variations of the with_tz() and force_tz() functions but all ...
0
votes
2
answers
93
views
How to split overlapping time intervals in R, assign precedence, and fill gaps with dummy events?
I’m working with machine events data in R, where each event has a start and end time, a unique event code, and a precedence level (ordered factor). Events may overlap, and I need to transform this ...
2
votes
3
answers
115
views
Which function can I to add 12 months to 2024-02-29 to get a value?
My code runs but I get an NA for 2024-02-29
library(lubridate)
my_date <- c(as.Date("2024-01-29"), as.Date("2024-02-29"))
next_year <- my_date+months(12)
next_year
#> [1] ...
0
votes
1
answer
96
views
Imputing date in time series dataframe
I have a dataframe in R with several ID, DAY and TIME and amount of a compound (AMT). Typically, for every ID, there should two records at every day, indicating two doses a day, typically in the ...
0
votes
3
answers
115
views
Converting numeric representation of date to date format in R
I have a dataset with dates in the format like 20170911.
Normally with other datasets I work with as.Date from the lubridate package and it works out pretty well.
However, when I apply the as.Date ...
1
vote
2
answers
115
views
setdiff in lubridate
Trying to figure out why this doesn't work. What I'm looking to do is break up test_int_1 into 3 segements -> before test_init_2, test_init_2, after test_init_2.
library(lubridate)
test_int_1 <-...
0
votes
1
answer
77
views
Parsing and working with microsecond-precision timestamps in R using dplyr
I'm planning to collect data with microsecond-precision timestamps in the format "DD/MM/YY HH:MM:SS.mmmuuun"? How would I parse in R and keep working in a dplyr pipeline?
Example:
"26/...
1
vote
1
answer
73
views
How do I drop duplicates within groups that were collected within 60min of one another?
I have camera trap data where I want to remove potentially duplicated animal detections. I am setting the interval as 60min (1 hour) so that any individual detected of the same species at the same ...
0
votes
1
answer
55
views
Does lubridate breakdown with large data.frames?
I have a large data.frame of about a million records. I'm trying to use lubridate to fix some dates and I get strange behavior. When I run it on the whole data.frame, it isn't able to parse any ...
3
votes
1
answer
65
views
Reformat data to include 2 minute time intervals
Example data are as follows:
library(dplyr)
library(lubridate)
library(tidyr)
set.seed(123)
dummy_data <- tibble(
focalbear_event = rep(c("event1", "event2"), each = 10),
...
0
votes
2
answers
62
views
How to pull first and last date from a dataframe with conditions and breaks?
I have data on water intensity that was collected every hour over many months (below is a subset of data). I need the first date that intensity was greater than 900 but only if it was greater than or ...
0
votes
0
answers
92
views
POSIXct conversion from character variable to datetime that causes year to start with '00xx' rather than '20xx'. How to fix this?
I am importing multiple csv files from one folder and I've noticed that when I do a conversion to convert a character datetime stamp, the year will read as '0024' rather than '2024'. How do I fix it ...
1
vote
3
answers
63
views
I need to count the number of days between a date and the last day that precipitation was greater than 12
I have a set of data with precipitation totals (Precip) for every day. I collected data at multiple pools. I need to calculate the number of days it has been since the last time it raied >12mm. If ...
1
vote
1
answer
54
views
Is there a way in R to subset or fragment lubridate interval objects to count the days in subsetted intervals? [closed]
Dear Stackoverflow Community,
I'm currently working with a dataset that contains start and end dates for individual travelers. However, I'm only interested in measuring the duration of time in days ...
0
votes
3
answers
58
views
Text date to date in R: from this format: Wed, 23 Feb 2022 00:00:00
I have a dataset with dates formatted like this:
> head(dfed$`POSTED DATE`)
[1] NA
[2] "Fri, 26 Jul 2024 00:00:00 (Brussels local time)"
[3] ...
3
votes
3
answers
310
views
How do I convert milliseconds to minutes and seconds?
I want to convert milliseconds values in my data to minutes and seconds (in the format MM:SS e.g. a value of 1772094 should become 29:32).
The toy data looks like this:
df <- data.frame(
ID = c(&...
0
votes
2
answers
35
views
using POSIXct to try and clean datetime cells in a table
I am trying to clean some tables in r and I have two columns that are in date time value. I know that date time value cells are difficult to deal with. Part of my problem is that the cells are mixed ...
-1
votes
2
answers
121
views
How to determine number of service dates and days between two snapshots in a dataframe?
I'm trying to take data from a nearly-weekly snapshot [some weeks are missing due to holidays, server issues, etc.] and determine the number of service dates between one snapshot and the next. I have ...
0
votes
1
answer
82
views
Plotting time intervals in R and tiling for several years
I am currently trying to plot the effort in sampling for my masters thesis, which looks something similar to this:
Figure 1:
So i have data for 3 years, and i want to reflect the exact days of the ...
0
votes
1
answer
34
views
Create variable Date
I want to create a variable Date from 3 variables in my dataframe :
data <- data %>%
mutate(Z49= if_else(
!is.na(Z49j) & !is.na(Z49m) & !is.na(Z49a) & Z49j != "&...
2
votes
0
answers
176
views
Why is the lubridate package returning invalid time zone error? [closed]
I recently updated to R version 4.4 and lubridate version 1.9.3 and started getting this error below when I try to add a period of time to a posixct variable.
Error in C_time_add(time, periods, ...