1

I am trying to convert a date with full month name, but it doesn't work Here are the errors

(1)

as.Date(c("May/27/2021"), "%B/%d/%Y")
[1] NA

(2)

library(lubridate)
mdy(c("11/03/2020", "November 3, 2020", "11032020"))
[1] "2020-11-03" "2020-03-20" "2020-11-03"

However, when I use numeric values for the months, it works well

Here is my session info

[1] zoo_1.8-11            tidyselect_1.2.0      xfun_0.33            
 [4] purrr_0.3.5           splines_4.2.1         lattice_0.20-45      
 [7] colorspace_2.0-3      vctrs_0.4.2           generics_0.1.3       
[10] htmltools_0.5.4       base64enc_0.1-3       utf8_1.2.2           
[13] survival_3.3-1        rlang_1.0.6           pillar_1.8.1         
[16] foreign_0.8-82        glue_1.6.2            DBI_1.1.3            
[19] RColorBrewer_1.1-3    readxl_1.4.1          splitstackshape_1.4.8
[22] jpeg_0.1-10           lifecycle_1.0.3       stringr_1.4.1        
[25] cellranger_1.1.0      munsell_0.5.0         gtable_0.3.1         
[28] htmlwidgets_1.6.1     latticeExtra_0.6-30   knitr_1.40           
[31] fastmap_1.1.0         lmtest_0.9-40         fansi_1.0.3          
[34] htmlTable_2.4.1       Rcpp_1.0.9            scales_1.2.1         
[37] backports_1.4.1       checkmate_2.1.0       Hmisc_4.8-0          
[40] deldir_1.0-6          interp_1.1-3          gridExtra_2.3        
[43] ggplot2_3.3.6         png_0.1-8             digest_0.6.29        
[46] stringi_1.7.8         dplyr_1.0.10          grid_4.2.1           
[49] cli_3.4.1             tools_4.2.1           sandwich_3.0-2       
[52] magrittr_2.0.3        tibble_3.1.8          Formula_1.2-4        
[55] cluster_2.1.3         tidyr_1.2.1           crayon_1.5.2         
[58] pkgconfig_2.0.3       MASS_7.3-57           Matrix_1.4-1         
[61] data.table_1.14.2     assertthat_0.2.1      rstudioapi_0.14      
[64] R6_2.5.1              rpart_4.1.16          nnet_7.3-17          
[67] compiler_4.2.1       

Can anyone help?

John legend2
  • 840
  • 9
  • 18
  • 1
    `as.Date(c("May/27/2021"), "%B/%d/%Y")` works fine for me. You may want to provide `sessionInfo()`. I suspect your `LOCALE` isn't set properly. – jay.sf Mar 06 '23 at 09:24
  • "LC_COLLATE=Korean_Korea.utf8;LC_CTYPE=Korean_Korea.utf8;LC_MONETARY=Korean_Korea.utf8;LC_NUMERIC=C;LC_TIME=Korean_Korea.utf8" – John legend2 Mar 06 '23 at 09:26
  • 1
    You left out the important part of `sessionInfo`, i.e. the beginning. ANyway, use this solution: https://stackoverflow.com/a/29197887/6574038 – jay.sf Mar 06 '23 at 09:28
  • 1
    See [Convert string to timestamps in R](https://stackoverflow.com/q/74024564/10488504). – GKi Mar 06 '23 at 09:29

0 Answers0