我正在嘗試將 Apple Health 匯出中的時間序列資料轉換為 xts 格式。但是,我無法獲得正確的資料格式。
new = health_df %>%
mutate(
Type = str_remove(type, "HKQuantityTypeIdentifier"),
Value = as.numeric(as.character(value)),
Date = as_datetime(creationDate)) %>%
filter(Type == 'HeartRate') %>%
select(Date, Type, Value)
> head(new)
# A tibble: 6 x 3
Date Type Value
<dttm> <chr> <dbl>
1 2021-07-27 13:12:32 HeartRate 80
2 2021-07-27 13:12:38 HeartRate 79
3 2021-07-27 13:12:42 HeartRate 76
4 2021-07-27 13:12:47 HeartRate 73
5 2021-07-27 13:12:52 HeartRate 71
6 2021-07-27 13:12:57 HeartRate 71
> class(new$Date)
[1] "POSIXct" "POSIXt"
> new = as.xts(new, dateFormat = "POSIXct")
Error in as.POSIXlt.character(x, tz, ...) :
character string is not in a standard unambiguous format
as.POSIXlt.character(x, tz, ...) 中的錯誤:字串不是標準的明確格式
我檢查了課程,但一切似乎都很好......我也嘗試指定格式
Date = as.POSIXct((Date), format = "%Y.%m.%d %H:%M:%S", tz="GMT"))
但這也不起作用。
也許我走錯了路,感謝您的幫助!最佳 C
uj5u.com熱心網友回復:
正如@phiver 提到的,您只需要在xts矩陣中保留數字資料。此外,由于該Date列已經是POSIXct您不需要更改的型別。嘗試 -
new_xts <- xts::xts(new$Value, order.by = new$Date)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/336864.html
下一篇:從資料幀創建多級.json檔案
