我试图将来自Apple导出的时代系列数据转换成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 formatas.POSIXlt.character(x,tz,.)中的错误:字符串不是标准格式的
我检查了全班,一切都很好.我还试图指定格式。
Date = as.POSIXct((Date), format = "%Y.%m.%d %H:%M:%S", tz="GMT"))但这也没用。
也许我走错了轨道,感谢你的帮助!最佳C
发布于 2021-10-26 11:00:38
正如@phiver所提到的,您只需要将数字数据保存在xts矩阵中。另外,由于Date列已经是POSIXct类型,所以不需要更改它。试着-
new_xts <- xts::xts(new$Value, order.by = new$Date)https://stackoverflow.com/questions/69721709
复制相似问题