lubridate

R-Studio. Error after installing lubridate: could not find function “dmy_hm”

孤街浪徒 提交于 2019-12-13 03:14:37
问题 First I installed lubridate: install.packages("lubridate") Installing package into ‘C:/Users/Llorenc Piera/AppData/Roaming/SPB_Data/R/win-library/3.4’ (as ‘lib’ is unspecified) trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/lubridate_1.7.4.zip' Content type 'application/zip' length 1365606 bytes (1.3 MB) downloaded 1.3 MB package ‘lubridate’ successfully unpacked and MD5 sums checked Warning in install.packages : cannot remove prior installation of package ‘lubridate’ Then I try

Expand periods to regularly occuring timestamps

£可爱£侵袭症+ 提交于 2019-12-13 02:58:34
问题 Had to modify the original post to include a better example I have a tibble with time based data with start time, end time and a class variable of the following general form: Code to make the table: library(lubridate) st <- c(ymd_hms("2016-01-01 00:35:00"), ymd_hms("2016-01-01 00:39:00"), ymd_hms("2016-01-01 00:54:00"), ymd_hms("2016-01-01 00:56:00"), ymd_hms("2016-01-01 00:57:00")) en <- c(ymd_hms("2016-01-01 00:36:00"), ymd_hms("2016-01-01 00:45:00"), ymd_hms("2016-01-01 00:55:00"), ymd_hms

transform date into dummy variable in R [duplicate]

时光总嘲笑我的痴心妄想 提交于 2019-12-13 02:58:01
问题 This question already has answers here : Find the day of a week (7 answers) Generate a dummy-variable (16 answers) Closed last year . I have this dataset df=structure(list(Data = structure(c(4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L), .Label = c("01.01.2018", "02.01.2018", "03.01.2018", "25.12.2017", "26.12.2017", "27.12.2017", "28.12.2017", "29.12.2017", "30.12.2017", "31.12.2017"), class = "factor"), Y = 1:10), .Names = c("Data", "Y"), class = "data.frame", row.names = c(NA, -10L)) Date is

how to calculate month difference in R

懵懂的女人 提交于 2019-12-12 20:13:41
问题 I have dates of format 2015-03 (i.e year-month). Now I want to calculate the month difference in between 2 dates. Example: difference between dates 2015-03 and 2014-12 should be 3 or 4 as December to March is 3 months or 4 months depending on whether we consider December or not. 回答1: a <- "2015-03" b <- "2014-12" a <- unlist(strsplit(a, "-")) b <- unlist(strsplit(b, "-")) a <- (as.numeric(a[1])*12) + as.numeric(a[2]) b <- (as.numeric(b[1])*12) + as.numeric(b[2]) difference <- diff(c(b,a))

Switch between dates and seconds in a well defined manner

老子叫甜甜 提交于 2019-12-12 19:38:32
问题 I run discrete event simulations where the time originates from dates. I think that simulations run much faster, when I convert all the dates to integers (relative time in seconds ). What is the best way, to switch between date and seconds in a well definied way where I want to set the reference time (e.g. "1970-01-01 00:00:00 GMT" or "2016-01-01 00:00:00 GMT" ) manually, the time zone and the origin (Not possible in lubridate ?) I thought I can use the origin for this purpose but it does not

how to convert excel internal coding for hours to hours in R? [duplicate]

与世无争的帅哥 提交于 2019-12-12 14:26:01
问题 This question already has answers here : Convert a decimal number to HH:MM (3 answers) Converting a time decimal/fraction representing days to its actual time in R? [duplicate] (2 answers) Convert fraction of day to POSIX times in R [duplicate] (2 answers) Closed 4 months ago . I have a hour variable stored as excel internal coding in R. See (https://www.ablebits.com/office-addins-blog/2015/06/23/excel-time-format-now-time-functions/), for example 0.4305556 is equivalent to 10:20:00 AM. How

R: calculate time difference between specific events

╄→尐↘猪︶ㄣ 提交于 2019-12-12 12:47:11
问题 I have the following dataset: df = data.frame(cbind(user_id = c(rep(1, 4), rep(2,4)), complete_order = c(rep(c(1,0,0,1), 2)), order_date = c('2015-01-28', '2015-01-31', '2015-02-08', '2015-02-23', '2015-01-25', '2015-01-28', '2015-02-06', '2015-02-21'))) library(lubridate) df$order_date = as_date(df$order_date) user_id complete_order order_date 1 1 2015-01-28 1 0 2015-01-31 1 0 2015-02-08 1 1 2015-02-23 2 1 2015-01-25 2 0 2015-01-28 2 0 2015-02-06 2 1 2015-02-21 I'm trying to calculate the

How to manipulate the time part of a date column?

本秂侑毒 提交于 2019-12-12 06:49:06
问题 How do I write this code ( hour is from lubridate package)? Objective: if hour part of PICK_DATE is later than 16:00, the ADJ_PICK_DATE should be next day 03:00. If the hour part of PICK_DATE is earlier than 03:00, then ADJ_PICK_DATE is to be same day 03:00. Problem is, when there is no change needed, the code still adds 3 hours to the PICK_DATE i.e. when the hour part of PICK_DATE is within 03:00 and 16:00. x$PICK_TIME <- cut(hour(x$PICK_DATE), c(-1, 2, 15, 24), c("EARLY", "OKAY", "LATE")) x

Questions associated with “Error: Aesthetics must be either length 1 or the same as the data”

一个人想着一个人 提交于 2019-12-12 05:59:18
问题 I understand the subject "Error: Aesthetics must be either length 1 or the same as the data" has been done a lot (plenty of reading available online), however, I still have some unresolved questions I am working with a dataset regarding all calls made to the Seattle Police Department in 2015. After I am done cleaning the data into an acceptable format I wind up with a dataset that is 62,092 rows and 13 columns (dataset name is SPD_2015). I would add a portion of the dataset to this question

How to perform a join based on intervals with dplyr?

徘徊边缘 提交于 2019-12-12 05:43:16
问题 I have a data frame containing two columns: a grouping variable and a interval period over which the grouping variable holds. I have another data frame with a date column and a value column. How can I join these two tables together somewhat efficiently with dplyr+tidyverse functions? library(dplyr) library(lubridate) ty <- data_frame(date = mdy(paste(1, 1 + seq(20), 2017, sep = "/")), y = c(rnorm(7), rnorm(7, mean = 2), rnorm(6, mean = -1))) gy <- data_frame(period = interval(mdy(c("01/01