i have vector with the following values.
> ga.nu$date
[1] "20150901" "20150902" "20150903" ...
> class(ga.nu$date)
[1] character
i want to convert his values to date in the following structure
> ga.nu$date
[1] "2015-09-01" "2015-09-02" "2015-09-03"
>class(ga.nu$date)
[1] "Date"
i've already trying
> as.Date(ga.nu$date,"%Y-%m-%d)
[1] NA NA NA
but i received null values
The format argument in the as.Date()
function refers not to the target format but to the one you are trying to convert. So simple change your code to:
ga.nu$date = as.Date(ga.nu$date,"%Y%m%d)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.