At the time of writing: a bug, see github issue 148.
A possible workaround, using tidyr and timetk and purrr. Using timetk to get the data into xts format, transform data into weekly and turn back into a data.frame format. Including nest
and unnest
from tidyr and map
from purrr. data.table is not needed but prints the data a lot better than tibbles.
library(tidyr)
library(timetk)
# library(purrr)
result <- dt %>%
group_by(symbol) %>%
nest() %>%
mutate(data = purrr::map(data, function(x) x %>%
select(date, Open = open, High = high, Low = low, Close = close) %>%
tk_xts(x, select = c(Open, High, Low, Close), date_var = date) %>%
to.weekly %>%
tk_tbl)) %>%
unnest(data) %>%
rename_with( ~ tolower(gsub("..", "", .x, fixed = T))) %>%
rename(date = index)
result %>%
data.table %>%
filter(date == "2017-02-03")
symbol date open high low close
1: AAPL 2017-02-03 30.2325 32.6225 30.155 32.27
2: GOOG 2017-02-03 814.6600 815.8400 790.520 801.49
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…