Thank you so much for your help. After running your suggested code I get the same output as you
Date Close Invest
<date> <dbl> <chr>
1 2015-04-01 1294. GOLD
2 2015-04-02 1288. GOLD
3 2015-04-03 1288. GOLD
4 2015-04-04 1288. GOLD
5 2015-04-05 1288. GOLD
6 2015-04-06 1305. GOLD
7 2015-04-07 1298. GOLD
8 2015-04-08 1291. GOLD
9 2015-04-09 1282. GOLD
10 2015-04-10 1293. GOLD
(although when I run str(Safe_Haven) the date column still shows as 'chr')?
str(Safe_Haven)
spec_tbl_df [15,342 × 3] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
$ Date : chr [1:15342] "04/01/2015 00:00" "04/02/2015 00:00" "04/03/2015 00:00" "04/04/2015 00:00" ...
$ Close : num [1:15342] 1294 1288 1288 1288 1288 ...
$ Invest: chr [1:15342] "GOLD" "GOLD" "GOLD" "GOLD" ...
- attr(*, "spec")=
.. cols(
.. Date = col_character(),
.. Close = col_number(),
.. Invest = col_character()
.. )
- attr(*, "problems")=<externalptr>
Sorry but when I'm trying to provide you with reproducible example, not able to read the file. Something I'm doing wrong? reprex::reprex()
library(tidyverse)
Safe_Haven %>% mutate(
Date_ = as.Date(Date,format = "%m/%d/%Y %H:%M"),
Datetime_ = strptime(Date,format = '%m/%d/%Y %H:%M'),
Close_ = as.numeric(str_remove_all(Close,','))
)
#> Error in mutate(., Date_ = as.Date(Date, format = "%m/%d/%Y %H:%M"), Datetime_ = strptime(Date, : object 'Safe_Haven' not found
Safe_Haven %>% mutate(
Date = as.Date(Date,format = "%m/%d/%Y %H:%M"),
Close = as.numeric(str_remove_all(Close,','))
)
#> Error in mutate(., Date = as.Date(Date, format = "%m/%d/%Y %H:%M"), Close = as.numeric(str_remove_all(Close, : object 'Safe_Haven' not found