Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sharing as.Date vs lubridate::as_date #5

Closed
englianhu opened this issue Dec 4, 2020 · 1 comment
Closed

sharing as.Date vs lubridate::as_date #5

englianhu opened this issue Dec 4, 2020 · 1 comment

Comments

@englianhu
Copy link
Owner

englianhu commented Dec 4, 2020

I noticed default as.Date function unable recognize the date of datatime format as we can see from 2015-01-19.

> tk_tbl(mbase)[14390:14410,]$index
 [1] "2015-01-16 23:50:00 JST" "2015-01-16 23:51:00 JST"
 [3] "2015-01-16 23:52:00 JST" "2015-01-16 23:53:00 JST"
 [5] "2015-01-16 23:54:00 JST" "2015-01-16 23:55:00 JST"
 [7] "2015-01-16 23:56:00 JST" "2015-01-16 23:57:00 JST"
 [9] "2015-01-16 23:58:00 JST" "2015-01-16 23:59:00 JST"
[11] "2015-01-17 00:00:00 JST" "2015-01-19 00:01:00 JST"
[13] "2015-01-19 00:02:00 JST" "2015-01-19 00:03:00 JST"
[15] "2015-01-19 00:04:00 JST" "2015-01-19 00:05:00 JST"
[17] "2015-01-19 00:06:00 JST" "2015-01-19 00:07:00 JST"
[19] "2015-01-19 00:08:00 JST" "2015-01-19 00:09:00 JST"
[21] "2015-01-19 00:10:00 JST"
> tk_tbl(mbase)[14390:14410,]$index %>% as.Date
 [1] "2015-01-16" "2015-01-16" "2015-01-16" "2015-01-16" "2015-01-16"
 [6] "2015-01-16" "2015-01-16" "2015-01-16" "2015-01-16" "2015-01-16"
[11] "2015-01-16" "2015-01-18" "2015-01-18" "2015-01-18" "2015-01-18"
[16] "2015-01-18" "2015-01-18" "2015-01-18" "2015-01-18" "2015-01-18"
[21] "2015-01-18"
> tk_tbl(mbase)[14390:14410,]$index %>% as_date
 [1] "2015-01-16" "2015-01-16" "2015-01-16" "2015-01-16" "2015-01-16"
 [6] "2015-01-16" "2015-01-16" "2015-01-16" "2015-01-16" "2015-01-16"
[11] "2015-01-17" "2015-01-19" "2015-01-19" "2015-01-19" "2015-01-19"
[16] "2015-01-19" "2015-01-19" "2015-01-19" "2015-01-19" "2015-01-19"
[21] "2015-01-19"
> tk_tbl(mbase)[14390:14410,]$index %>% as.Date %>% class
[1] "Date"
> tk_tbl(mbase)[14390:14410,]$index %>% as_date %>% class
[1] "Date"

sharing as.Date vs lubridate::as_date

Here is relevant question but in Lubridate as_date and as_datetime differences in behavior and Dates and Times in R Without Losing Your Sanitythere will be use in intraday high-frequency-trading.

@englianhu
Copy link
Owner Author

as.Date(tz = 'Asia/Tokyo') or as_date(tz = 'Asia/Tokyo') will solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant