Я пытаюсь создать еженедельные средние значения на основе объектов xts, которые я разделил на список с помощью, но я получаю сообщение об ошибке:
Error in isOrdered(INDEX) :
(list) object cannot be coerced to type 'double'
Я пытался использовать period.applyfunction.
> str(rate_data)
'data.frame': 887079 obs. of 3 variables:
$ LoadDate : Date, format: "2018-03-05" "2018-02-21" "2018-02-07" ...
$ laneid : Factor w/ 6905 levels " _FL_Van"," _PA_Van",..: 4629
579 6538 5944 1213 1213 6029 5564 4287 5745 ...
$ TruckPayPerMile: num 3.62 1.5 1.33 2.39 1.01 ...
> head(rate_data)
LoadDate laneid TruckPayPerMile
1 2018-03-05 OH_NY_Van 3.6231
2 2018-02-21 CA_AR_Reefer 1.5046
3 2018-02-07 WA_TX_Van 1.3333
4 2018-01-31 TX_MA_Van 2.3852
5 2018-01-29 FL_SC_Van 1.0149
6 2018-01-30 FL_SC_Van 1.0683
rate_data_xts <- xts(rate_data, rate_data[ ,-2], order.by = rate_data[ ,2])
lanes_xts <- split(rate_data_xts, rate_data_xts$laneid)
tx_ca_reefer <- lanes_xts[["TX_CA_Reefer"]]
head(tx_ca_reefer)
> head(tx_ca_reefer)
LoadDate laneid TruckPayPerMile
2018-01-28 2018-01-28 TX_CA_Reefer 1.6850
2018-01-28 2018-01-28 TX_CA_Reefer 2.5128
2018-01-29 2018-01-29 TX_CA_Reefer 2.4077
2018-01-29 2018-01-29 TX_CA_Reefer 1.3610
2018-01-29 2018-01-29 TX_CA_Reefer 1.8241
2018-01-29 2018-01-29 TX_CA_Reefer 1.8703
Warning message:
In zoo(rval, index(x)[i]) :
some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique
end_points <- map(lanes_xts, endpoints, on = 'weeks')
lanes_weekly_xts <- period.apply(lanes_xts, INDEX = end_points, FUN = mean)
Error in isOrdered(INDEX) :
(list) object cannot be coerced to type 'double'
Что мне нужно, так это средненедельное значение для каждого объекта xts в списке.Любая помощь будет принята с благодарностью.