I have imported some data. The issue is that the dates are in the format 20140101 for example.
The standard format is 2014-01-01, when I try as.Date(datecolumn, format = '%Y-%m-&d)
I get very strange year values.
How can I make my dates to standard date format quickly and efficiently?
I can do it by using paste0
, but surely there must be a better way?
Output
> head(backup)
quote_date open high low close volume value
1 20151203 263.10 263.10 263.10 263.10 0 0
2 20151202 264.51 264.51 264.51 264.51 0 0
3 20151201 261.91 261.91 261.91 261.91 0 0
4 20151130 260.68 260.68 260.68 260.68 0 0
5 20151127 256.75 256.75 256.75 256.75 0 0
6 20151125 253.93 253.93 253.93 253.93 0 0
> str(backup)
'data.frame': 960 obs. of 7 variables:
$ quote_date: int 20151203 20151202 20151201 20151130 20151127 20151125 20151124 20151123 20151120 20151119 ...
$ open : num 263 265 262 261 257 ...
$ high : num 263 265 262 261 257 ...
$ low : num 263 265 262 261 257 ...
$ close : num 263 265 262 261 257 ...
$ volume : int 0 0 0 0 0 0 0 0 0 0 ...
$ value : int 0 0 0 0 0 0 0 0 0 0 ...
> head(as.Date(backup$quote_date, format = '%Y%m%d'))
[1] NA NA NA NA NA NA