【发布时间】:2015-03-22 20:00:27
【问题描述】:
随着时间的推移,我每天都会收集数据。我想将数据绘制为总结每日数据的箱线图。我见过的大多数示例都以daily 或每月为基础收集数据,并从中制作箱线图。
举个例子:
library(xts)
dates=c(rep("2011-02-11",8),rep("2011-02-13",8),rep("2011-02-19",8))
measure=rnorm(length(dates))
example <- as.xts( measure,order.by = as.Date( dates ))
boxplot(coredata(example), order.by=index(example),.CLASS = "xts")
我最终没有按日期分开。
我想不通。我认为这可能与 R 如何处理 X 值有关,我听说它会将它们变成因子。任何帮助将不胜感激。
【问题讨论】:
-
coredata()删除所有日期信息。这就是 zoo/xts 对象的index中存储的内容。 -
这是真的,但是如果我简单地询问
boxplot(example),它会给我错误Error in try.xts(c(1.03773548252495e-317, 2.06236439159703e-317, 7.76223611312559e-316, : Error in xts(coredata(x), order.by = index(x), .CLASS = "xts", ...) : order.by requires an appropriate time-based object,可以通过询问boxplot(coredata(example) ~ index(example))来临时修复,但这给我留下了均匀间隔的箱线图,而日期是不均匀的。