Lubridate::mdy Error

Hi, I'm from Colombia and I have this issue:

When I use this code individually, this show me the result:

text = "Nov 05, 2020"
lubridate::mdy(str_remove_all(str_to_lower(text), ","))
"11-05-2020"

But when I use it in a for loop, it showed me "18571" instead of a datetime.

Before, the for loop worked fine...but yesterday and today it hasn't been working.

What happened? :frowning:

actually running the code shows it doesnt work, ... there is a bracket problem as you open 3 but close 2.

I corrected it. Thanks!
But it's not the problem :confused:

What your problem is, is mysterious.
The speculation must be that your data , the input to V3, is not as you believe it to be ...
Can you demonstrate that it is ?

please use dput and provide sample data and code showing the error.

#example of the function discussed being used repeatedly
library(tidyverse)
library(lubridate)

(df0 <- tibble(text = c("Nov 05, 2020","Dec 06, 2021")))

mutate(df0,
       date=lubridate::mdy(str_remove_all(str_to_lower(text), ","))
       )
# A tibble: 2 x 2
  text         date      
  <chr>        <date>    
1 Nov 05, 2020 2020-11-05
2 Dec 06, 2021 2021-12-06

image

When run mutate like you do, it worked!
Thanks for all !!!!!
I will change my class data from dataframe to Tibble.

With this code:

for (i in 1:nrow(data01)){
    data01[i, 2] <- mdy(str_remove_all(str_to_lower(data01[i, 2]), ","))
    data01[i, 4] <- mdy(str_remove_all(str_to_lower(data01[i, 4]), ","))
}

Result:
image

With your code:

datay <- data01 %>% mutate(exdividend_date = mdy(str_remove_all(str_to_lower(data01[i, 2]), ","))) %>%
        mutate(payment_date = mdy(str_remove_all(str_to_lower(data01[i, 4]), ",")))

Result:
image

I'm sorry because I don't know how to use dput(). I tried, but I didn't get it. :confused:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.