lubridate

Adding 15 business days in lubridate

怎甘沉沦 提交于 2019-11-28 10:26:43
I have a long list of start dates of a certain procedure. Rules require the procedure to be completed in, at most, 6 business days. I wish to compute the deadline. Using lubridate in R, I can get a six-day deadline thus > library(lubridate) > date.in <- dmy(c("30-8-2001", "12-1-2003", "28-2-2003", "20-5-2004")) > date.in [1] "2001-08-30 UTC" "2003-01-12 UTC" "2003-02-28 UTC" "2004-05-20 UTC" > deadline.using.days <- date.in + days(6) > deadline.using.days [1] "2001-09-05 UTC" "2003-01-18 UTC" "2003-03-06 UTC" "2004-05-26 UTC" Is there an easy way to add six business days --- i.e., skipping

Calculating Time Difference between two columns

旧城冷巷雨未停 提交于 2019-11-28 10:14:59
After converting factors in POSIXCT format and then applying datetime format, I want to take the difference of datetime between 2 pos1 and pos2. However, when I do that for a specific item I get the right answer in the console but when I do the operation on the whole set the console outputs just number and also the dateframe reflects those number as you can see. How can I get the hours in the dataframe when I am trying to take the difference? I am using lubridate package, is there any function to do so? Here is some example code/picture of the data in RStudio describing it CR_Date <- data

Summing rows by month in R

╄→尐↘猪︶ㄣ 提交于 2019-11-28 10:04:18
So I have a data frame that has a date column, an hour column and a series of other numerical columns. Each row in the data frame is 1 hour of 1 day for an entire year. The data frame looks like this: Date Hour Melbourne Southern Flagstaff 1 2009-05-01 0 0 5 17 2 2009-05-01 2 0 2 1 3 2009-05-01 1 0 11 0 4 2009-05-01 3 0 3 8 5 2009-05-01 4 0 1 0 6 2009-05-01 5 0 49 79 7 2009-05-01 6 0 425 610 The hours are out of order because this is subsetted from another data frame. I would like to sum the values in the numerical columns by month and possibly by day. Does anyone know how I can do this? I

Extract Fiscal Year with R Lubridate

独自空忆成欢 提交于 2019-11-28 09:14:00
问题 I'll create several dates. library(lubridate) x <- ymd(c("2012-03-26", "2012-05-04", "2012-09-23", "2012-12-31")) I can extract the year and quarter from these x values. quarter(x, with_year = TRUE, fiscal_start = 10) [1] 2012.2 2012.3 2012.4 2013.1 But I can't seem to extract just the fiscal year. This doesn't work, but what will? year(x, with_year = TRUE, fiscal_start = 10) I receive the following error message: Error in year(x, with_year = TRUE, fiscal_start = 10) : unused arguments (with

R: how to filter a timestamp by hour and minute?

爷,独闯天下 提交于 2019-11-28 08:47:47
问题 I am struggling with the following example time = c('2013-01-03 21:59:21.549', '2013-01-04 22:00:21.549', '2013-01-05 22:01:21.222', '2013-01-06 22:06:23.559' ) value = c(1,2,3,4) data <- data_frame(time, value) data <-data %>% mutate(time = ymd_hms(time)) > data # A tibble: 4 × 2 time value <dttm> <dbl> 1 2013-01-03 21:59:21 1 2 2013-01-04 22:00:21 2 3 2013-01-05 22:01:21 3 4 2013-01-06 22:06:23 4 How can I write a dplyr::filter statement than only keeps observations between 21:59 and 22:01

Format multiple date formats in one columns using lubridate

偶尔善良 提交于 2019-11-28 08:35:59
问题 Sometimes I am given data sets that has two different date formats but common variables that have to been joined into one dataframe. Over the years, I've tried various solutions to get around this workflow hassle. Now that I've been using lubridate, it seems like many of these problems are easily solved. However, I am encountering some behaviour that seems weird to me though I imagine there is a good explanation that is beyond me. Say I am given a data set with different date formats that I

row not consolidating duplicates in R when using multiple months in Date Filter

谁都会走 提交于 2019-11-28 02:03:19
I am using the following code to summarize my data by a column library(data.table, warn.conflicts = FALSE) library(lubridate, warn.conflicts = FALSE) ################ ## PARAMETERS ## ################ # Set path of major source folder for raw transaction data in_directory <- "C:/Users/NAME/Documents/Raw Data/" # List names of sub-folders (currently grouped by first two characters of CUST_ID) in_subfolders <- list("AA-CA", "CB-HZ") # Set location for output out_directory <- "C:/Users/NAME/Documents/YTD Master/" out_filename <- "OUTPUT.csv" # Set beginning and end of date range to be collected -

Check if a date is within an interval in R

邮差的信 提交于 2019-11-28 00:12:09
I have these three intervals defined: YEAR_1 <- interval(ymd('2002-09-01'), ymd('2003-08-31')) YEAR_2 <- interval(ymd('2003-09-01'), ymd('2004-08-31')) YEAR_3 <- interval(ymd('2004-09-01'), ymd('2005-08-31')) (in real life, I have 50 of these) I have a dataframe (called df ) with a column full of lubridate formatted dates. I'd like to append a new column on df which has the appropriate value YEAR_n , depending on which interval the date falls within. Something like: df$YR <- ifelse(df$DATE %within% YEAR_1, 1, NA) but I'm not sure how to proceed. I need to somehow use an apply I think? Here's

Plot dates on the x axis and time on the y axis with ggplot2

試著忘記壹切 提交于 2019-11-27 23:05:57
I have read in a series of 37 dates and times that an event happened. It is now sitting as a POSIXlt object. I want a graphic representation of the times that the events happened on each day. So the x axis should be the date and y axis should be the time of day. then I tried to plot it with ggplot2 qplot(day(dttm), hour(dttm)) That is kind of what I want but it does not have the resolution of minutes. How do I have hours and minutes included in the y axis? Here is some sample data dttm [1] "2011-11-16 10:39:20" "2011-11-16 10:56:32" "2011-11-16 11:52:43" "2011-11-16 12:10:42" [5] "2011-11-16

dplyr, lubridate : how to aggregate a dataframe by week?

☆樱花仙子☆ 提交于 2019-11-27 19:53:28
Consider the following example library(tidyverse) library(lubridate) time <- seq(from =ymd("2014-02-24"),to= ymd("2014-03-20"), by="days") set.seed(123) values <- sample(seq(from = 20, to = 50, by = 5), size = length(time), replace = TRUE) df2 <- data_frame(time, values) df2 <- df2 %>% mutate(day_of_week = wday(time, label = TRUE)) Source: local data frame [25 x 3] time values day_of_week <date> <dbl> <fctr> 1 2014-02-24 30 Mon 2 2014-02-25 45 Tues 3 2014-02-26 30 Wed 4 2014-02-27 50 Thurs 5 2014-02-28 50 Fri 6 2014-03-01 20 Sat 7 2014-03-02 35 Sun 8 2014-03-03 50 Mon 9 2014-03-04 35 Tues 10