Hi, when I am importing CSV file. One of data column is date. Nad Date format is in dd/mmm/yyyy formate e.g. 03/Apr/2020.
But when I try to assign in date format, R does not recognise and make date column in NA.
Could you please help me how I can resolve this issue?
You can use th dmy() function from the lubridate package.
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#>
#> date
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:lubridate':
#>
#> intersect, setdiff, union
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
DF <- data.frame(MyDate = c("14/Feb/2020", "05/May/2020"))
str(DF)
#> 'data.frame': 2 obs. of 1 variable:
#> $ MyDate: Factor w/ 2 levels "05/May/2020",..: 2 1
DF <- DF %>% mutate(MyDate = dmy(MyDate))
str(DF)
#> 'data.frame': 2 obs. of 1 variable:
#> $ MyDate: Date, format: "2020-02-14" "2020-05-05"
Created on 2020-04-09 by the reprex package (v0.3.0)
1 Like
FJCC
Thank you indeed
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.