Questions tagged [lubridate]

lubridate is an R package that makes it easier to work with dates and time objects.

The lubridate package facilitates working with dates and times in . lubridate also expands the type of mathematical operations that can be performed with date-time objects. It introduces three new time span classes borrowed from :

  • durations, which measure the exact amount of time between two points
  • periods, which accurately track clock times despite leap years, leap seconds, and day light savings time
  • intervals, a protean summary of the time information between two points

Repositories

Vignettes

Other resources

Related tags

2520 questions
0
votes
1 answer

lubridate extract year from date column

Based on the data and code below, when I try to extract year from the date column, I get the following error: Error in as.POSIXlt.character(x, tz = tz(x)) : character string is not in a standard unambiguous format Purpose: Create year and…
Ed_Gravy
  • 1,841
  • 2
  • 11
  • 34
0
votes
2 answers

How to get date from a condition on certain column

I am working of data that has wave number and they represent the data for a certain month of a certain year. The data is bi-monthly so an increment in wave column means the increase of 2 months The column of wave looks something like…
Ali Inayat
  • 41
  • 5
0
votes
2 answers

Add a column in dataframe by datetime conditions of another dataframe

I have the following data example. first data: structure(list(cycle_rounded = structure(c(1604188800, 1604190600, 1604192400, 1604194200, 1604196000, 1604197800, 1604199600, 1604201400, 1604203200, 1604205000, 1604206800, 1604208600, 1604210400,…
Wilson Souza
  • 830
  • 4
  • 12
0
votes
0 answers

How to convert the below character variables to date

how to convert it to date TV "Jan-16", "Feb-16", "Mar-16", "Apr-16", "May-16", "Jun-16", "Jul-16", "Aug-16",
0
votes
0 answers

Convert year and day of year to month

I have files that are named according to year and day of year. How do I convert day of year to month? Basic example: library(tidyverse) library(lubridate) (mydates <- tibble(year = c(2010, 2020), dayofyear = c(001, 365), …
derelict
  • 3,657
  • 3
  • 24
  • 29
0
votes
2 answers

How to stop lubridate dropping the hour when it's just gone midnight

How do I get lubridate to keep the hour when the time is e.g. 00:30:42? hms() wants to output 30M 42S, whereas I want 0H 32M 40S. library(lubridate) hms("00:32:40") [1] "32M 40S" The reason I need this is because I'm using the time to put together…
Mike
  • 921
  • 7
  • 26
0
votes
1 answer

Join two dataframes by the most closest datetime

I would like to join these 2 data frames by the closest time of df1 to df2. Keeping all datetime present on df2 and the column validated filled with the name "coral_sol" and column N filled with NA. df1 <- structure(list(validated = c("coral_sol",…
Wilson Souza
  • 830
  • 4
  • 12
0
votes
1 answer

In dplyr, how to use a value in a column to specify another column to index

I have data in the form of a list of objects (settings from our analysis machine). Some objects in the list are times, stored as a list containing hours, minutes and seconds. I then have a 'directory', which contains the names of the objects in the…
Mike
  • 921
  • 7
  • 26
0
votes
1 answer

How can I calculate the number of nights PER MONTH between two dates in R even if they are across two months?

I have hotel booking data and there's an arrival and a departure date. I have successfully counted the days in between using difftime but I would now like to know the number of dates per month. If both arrival and departure date are within one month…
Sofia
  • 21
  • 3
0
votes
0 answers

How to convert "2021-05-19T19:30:00.000Z" to datetime?

I'm using R. The data is coming from a SQL database, and it's being imported as a string/char. I'm trying to convert this string ("2021-05-19T19:30:00.000Z") into a datetime. There are multiples in the dataset like this, and some look normal…
0
votes
0 answers

creating a non-standard repeating datetime series in R

My objective is to use R (or potentially python) to create a datetime series for 3 non-standard work shifts (A, B, C) in order to link those shifts to datetime events in another table. The basic pattern is 3 24-hour alternating on/off periods…
tbtvem
  • 1
  • 2
0
votes
1 answer

using R lubridate, find value for the same columns from the same period last year

I have sales data for different vendors by year, product, and region. I want to compute the year-over-year in vendor market share. Here's a sample data frame named…
EPBaron
  • 11
  • 3
0
votes
3 answers

Converting format %H %M %S (no leading 0s) to HH:MM:SS in r

I realize this may be a very basic question, but I am under a time crunch and cannot for the life of me figure this out. Someone altered this data I need to use to go from HH:MM:SS to %%H %%M %%S without leading 0s when these values are not double…
julianne
  • 13
  • 4
0
votes
1 answer

How to change a number into datetime format in R

I have a vector a = 40208.64507. In excel, I can automatically change a to a datetime: 2010/1/30 15:28:54 by click the Date type. I tried some methods but I cannot get the same result in R, just as in excel. a = 40208.64507 # in Excel, a can change…
zhiwei li
  • 1,635
  • 8
  • 26
0
votes
3 answers

How do I change a ymd date to a dmy date with lubridate?

So, let's say I have data with a column date. library(dplyr) library(lubridate) df <- data.frame( nr = c(1, 2), date = c(20170131, 20081028) ) df2 <- df %>% mutate(date = ymd(date)) Now my data has the dates in proper date format…
Nina van Bruggen
  • 393
  • 2
  • 13