lubridate

convert invalid date to a valid date like value using R

北战南征 提交于 2020-03-16 08:09:31
问题 I have a dataframe like as shown below d1 <- c('21/01/2052 9:02','12/30/2042 9:25','10134-5-28 0:0:0','10109-12-27 0:0:0','10176-6-7 0:0:0') d2 <- c('22/03/2052 9:22','31/10/2043 9:25','10134-6-02 0:0:0','10109-12-30 0:0:0','10176-6-9 0:0:0') df_test <- c(d1,d2) Input I tried something like below using lubridate package but doesn't seem to help mdy_hm(df_test$d1) This resulted in a warning message and resulted in NAs for invalid values It's fine if invalid dates can't be processed and returns

Splitting Character String to Extract Date and Time [duplicate]

∥☆過路亽.° 提交于 2020-03-04 18:57:10
问题 This question already has answers here : Split date time (6 answers) Closed 18 days ago . I have a character string in a column of a tibble that looks like Nov 01, 2019 8:00:41 AM CDT . I would like to create new columns of the mentioned column, Date and Time. What is the best approaches into doing this? Lubridate? Time <- tibble(Call = 1, Date_Time = 'Nov 01, 2019 8:00:41 AM CDT') Time %>% mutate(Date_Time = mdy(`Contact Start Date/Time`)) I tried the code above but, my new column had

Mutate based on two conditions in R dataframe

江枫思渺然 提交于 2020-02-24 11:43:11
问题 I have a R dataframe which can be generated from the code below DF <- data.frame("Person_id" = c(1,1,1,1,2,2,2,2,3,3), "Type" = c("IN","OUT","IN","ANC","IN","OUT","IN","ANC","EM","ANC"), "Name" = c("Nara","Nara","Nara","Nara","Dora","Dora","Dora","Dora","Sara","Sara"),"day_1" = c("21/1/2002","21/4/2002","21/6/2002","21/9/2002","28/1/2012","28/4/2012","28/6/2012","28/9/2012","30/06/2004","30/06/2005"),"day_2" = c("23/1/2002","21/4/2002","","","30/1/2012","28/4/2012","","28/9/2012","","")) What

Arrange function: Conflict between lubridate and dplyr R

丶灬走出姿态 提交于 2020-01-30 13:01:06
问题 I want to rearrange a df with the function arrange from dplyr . The problem is that seems that these two packages have a conflict when I have another column (let's say v2) distinct from the column I want to arrange the df: library(dplyr) library(lubridate) start_dates <- as.Date(1:10, origin = "2018-01-01") my_df <- data.frame(x = 10:1, y = interval(start_dates, start_dates + 1), z=c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J")) my_df %>% arrange(z) Error in arrange_impl(.data, dots) :

lubridate: how to parse month-year? [duplicate]

人盡茶涼 提交于 2020-01-26 01:47:08
问题 This question already has answers here : Converting year and month (“yyyy-mm” format) to a date? (7 answers) Closed 3 years ago . I have a column of dates as follows, > mymonth = c('10/2015','11/2016','12/2016') > data <- data_frame(mymonth) > data # A tibble: 3 × 1 mymonth <chr> 1 10/2015 2 11/2016 3 12/2016 Here, obviously, my month corresponds to a particular month in the year. October 2015, November 2015 and December 2015. I cannot parse these dates correctly with lubridate . It is

How to convert character and dates to dates?

五迷三道 提交于 2020-01-25 06:52:12
问题 My data comes from excel. The dates are in dd/mm/yyyy format: certificado$fecha <- c("22/02/2019", "43679", "22/02/2019", "22/01/2019", "28/10/2019", "18/09/2019") However, R is reading some dates as mm/dd/yyyy. My code is supposed to convert all of them to an specific format. certificados$Fecha <- as.Date(certificados$Fecha,format = "%d/%m/%Y") But im getting NAs due to date format issues. 回答1: If you cannot fix this at the source, this code finds both formats: vec <- c("22/02/2019", "43679"

Apply and lubridate

烈酒焚心 提交于 2020-01-25 06:07:13
问题 I have a problem with dates convertion. If I use ymd in apply, it returns a numeric, or if I use only ymd it's works. Someone would have any idea ? library(lubridate) a <- data.frame(dates1=c("2011-01-01",'2011-02-01','2011-03-01'), dates2=c("2013-01-01",'2013-02-01','2013-03-01')) apply(a, 2, FUN = function(x) ymd(x)) dates1 dates2 [1,] 1293840000 1356998400 [2,] 1296518400 1359676800 [3,] 1298937600 1362096000 ymd(a$dates1) [1] "2011-01-01 UTC" "2011-02-01 UTC" "2011-03-01 UTC" ymd(a$dates2

combine multiple rows into one time interval

我的梦境 提交于 2020-01-25 02:56:30
问题 I have a data frame which is made up of the date and time a number of tagged animals visited a feeder. it looks like this - ID date_time A 2019-11-02 08:07:47 B 2019-11-02 08:07:48 A 2019-11-02 08:07:49 A 2019-11-02 08:07:50 A 2019-11-02 08:09:12 A 2019-11-02 08:09:13 B 2019-11-02 08:09:17 I'd like to lump all data points recorded within n seconds of each other into a single row so that it looks like this - ID start_date_time. end_date_time A 2019-11-02 08:07:47 2019-11-02 08:07:50 B 2019-11

Convert to local time zone from latitude and longitude R

牧云@^-^@ 提交于 2020-01-23 19:45:55
问题 I have one data frame with a lot of locations (around 30.000), and I need to convert the time of each location for the local time. I tried some ideas like this one, and this one. But they did not work for me. I have data like this: dt = data.table(date = c("2018-01-16 22:02:37", "2018-01-16 22:54:00", "2018-01-16 23:08:38"), lat = c(-54.5010, -54.5246, -54.5285), long = c(-25.0433, -25.0929, -25.0832)) And I expected this output: date lat long 2018-01-16 20:02:37 -54.5010 -25.0433 2018-01-16

Format Date to Year-Month in R

混江龙づ霸主 提交于 2020-01-22 19:55:28
问题 I would like to retain my current date column in year-month format as date. It currently gets converted to chr format. I have tried as_datetime but it coerces all values to NA. The format I am looking for is: "2017-01" library(lubridate) df<- data.frame(Date=c("2017-01-01","2017-01-02","2017-01-03","2017-01-04", "2018-01-01","2018-01-02","2018-02-01","2018-03-02"), N=c(24,10,13,12,10,10,33,45)) df$Date <- as_datetime(df$Date) df$Date <- ymd(df$Date) df$Date <- strftime(df$Date,format="%Y-%m")