Here is my example.
my_df <- data.frame(col_1 = c(1,2),
col_2 = c(as.Date('2018-11-11'), as.Date('2016-01-01')))
dates_list <- my_df$col_2
for(el in dates_list){
print(el)
}
It generates:
17846
16801
How do I output dates instead? I can do it with explicit index, but would like to have simpler solution
1) Use
as.list
:giving:
2) or not quite as nice but one can iterate over the indexes:
You can also use
as_date
function from lubridate.The cause of the problem could be that
dates_list <- my_df$col_2
coerces the column to a date vector:so another solution would be to resolve this, as follows: