lubridate

Start first day of week of the year on Sunday and end last day of week of the year on Saturday

谁说我不能喝 提交于 2019-12-11 04:11:31
问题 I have recently encountered a problem in R dealing with the dates. The last day of 2015 (2015-12-31) falls on Thursday, meaning last week of the year only contains 5 days if I consider Sunday as the start day of my week. Now, I would like 2016-01-01 and 2016-01-02, which fall on Friday and Saturday, to be associated with week 53, and start week 1 on 2016-01-03, which falls on Sunday. require(lubridate) range <- seq(as.Date('2015-12-26'), by = 1, len = 10) df <- data.frame(range) df$WKN <- as

Why is there no lubridate:::update function?

北慕城南 提交于 2019-12-11 01:57:57
问题 As said in the title: Why is there no such function? Or in a different way: What is the type of the function? When I type ?update I get something from stats package, but there is a lubridate function as described here on page 7. There also seems to be a lubridate:::update.Date function, but I can't find any explanations for that function. Backround : I use the function in a package and I only got it to work after I used the Depends: in the decription file. Initially I wanted to use lubridate:

R lubridate package date-time creation omits time at midnight

被刻印的时光 ゝ 提交于 2019-12-11 01:11:33
问题 I am trying to create date-time using lubridate package, and I've tried the following values: library(lubridate) ymd_hms("2017-07-02 23:00:00") [1] "2017-07-02 23:00:00 UTC" ymd_hms("2017-07-02 00:00:00") [1] "2017-07-02 UTC" It seems that if you type the time at midnight, 00:00:00, the ymd_hms() method ignores the time value, and the result becomes a date. Is there any way to show the 00:00:00 in the result? Thanks a lot! 回答1: So I just got my own answer to this question after google

Parsing Dates from Text in R

ぐ巨炮叔叔 提交于 2019-12-11 00:05:55
问题 I repeatedly come across the problem to parse dates from relatively unstructured text documents where the date is embedded in the text and its position and format varies from case to case. Some example text is: "Name of the city, name of the country, July 1st, 2015 - The group announces that it has completed the project initiated in November 2011. It has launched 12 other initiatives. The average revenue per initiative is USD 100." I would like to extract the date string "July 1st, 2015" from

dplyr's filter not working on lubridate's timeformats?

回眸只為那壹抹淺笑 提交于 2019-12-10 20:25:16
问题 When trying to answering this question, I run against a problem with using filter from dplyr -package on a lubridat -period column. Example data: df <- data.frame(time = ms(c('0:19','1:24','7:53','11:6')), value = 1:4) Using: filter(df, time > ms('5:00')) # or: filter(df, time > '5M 00S') results in the wrong output: time value 1 53S 3 2 1M 6S 4 Warning message: In format.data.frame(x, digits = digits, na.encode = FALSE) : corrupt data frame: columns will be truncated or padded with NAs

Extract time (HMS) from lubridate date time object?

只愿长相守 提交于 2019-12-10 19:43:51
问题 I have the following datetime: t <- "2018-05-01 23:02:50 UTC" I want to split it to time and date. When I apply date(t) I get the date part. But when I use lubridate's hms , parse_date_time and other functions to do this in "HMS" order I get NA . I have checked other answers here on SOF but for some reason it gives me NA . Please advise how to extract it. I want to understand why: strftime(t, format="%H:%M:%S") will do the job but what I am missing in lubridate::hms or parse_date_time ? 回答1:

Shade background of ggplot according to month

南楼画角 提交于 2019-12-10 18:58:41
问题 This code: df <- data.frame(day <- 0:365, value = 1) library(ggplot2) ggplot(df, aes(day, value)) + geom_blank() + scale_x_continuous(breaks = seq(0, 365, 10)) + theme_bw() Produces this plot: Using R code, I want to shade the background of the plot according to which day falls in which month. I want the plot to look like below (the plot background is Photoshopped). I would be particularly interested in a solution that uses lubridate . 回答1: Here's part of the solution using geom_raster .

Vectorised time zone conversion with lubridate

守給你的承諾、 提交于 2019-12-10 14:19:49
问题 I have a data frame with a column of date-time strings: library(tidyverse) library(lubridate) testdf = data_frame( mytz = c('Australia/Sydney', 'Australia/Adelaide', 'Australia/Perth'), mydt = c('2018-01-17T09:15:00', '2018-01-17T09:16:00', '2018-01-17T09:18:00')) testdf # A tibble: 3 x 2 # mytz mydt # <chr> <chr> # 1 Australia/Sydney 2018-01-17T09:15:00 # 2 Australia/Adelaide 2018-01-17T09:16:00 # 3 Australia/Perth 2018-01-17T09:18:00 I want to convert these date-time strings to POSIX date

Is there a way to assign DST transitions automatically in lubridate?

与世无争的帅哥 提交于 2019-12-10 11:40:01
问题 I have date-time pairs in a csv file that look like 11/4/2012 in one column and 12:06:08 AM in the neighboring column. They are recorded in local time (i.e., they switch to PST and PDT at the appropriate times), but there is no tz or DST indicator in the file. The only visible way to detect that is that the sequence of times does funny things. For example, on November 4, 2012, I have a sequence of times like 12:51:20 AM 1:13:08 AM 1:24:58 AM 1:40:28 AM 1:48:08 AM 1:54:08 AM 1:56:58 AM 1:04:28

changing POSIXct date vaules to first day of each week

眉间皱痕 提交于 2019-12-10 04:15:13
问题 I want to calculate the average Dist for each week using these data (below) while preserving the benefits of a using the POSIXct time class. df <- structure(list(IndID = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), class = "factor", .Label = "AAA"), Date = structure(c(1329436800, 1329458400, 1329480000, 1329501600, 1329523200,