【发布时间】:2015-10-22 01:56:32
【问题描述】:
我有这四个以秒为单位的数字:
maxtime = 240.0333
mintime = 181.1333
times1 = c(179.1333, 183.8000, 192.3000, 194.0000, 196.2500, 198.8333, 203.4333, 217.8167)
times2 = c(183.1333, 187.8000, 196.3000, 198.0000, 200.2500, 202.8333, 207.4333, 221.8167)
您会注意到times1 和times2 的长度相同。每个对应的元素相隔 4 秒。也就是说,times1 比 times2 早 4 秒。
说明我的问题的最佳方式是像这样绘制这些数据:
library(ggplot2)
library(dplyr)
dfplot<- data.frame(ymin=times1, ymax=times2)
data.frame(x=c(rep("min",length(times1)), rep("max",length(times1))),
y=c(times1,times2),
id=1:length(times1)) %>%
ggplot(., aes(id,y,group=id)) +
geom_path(lwd=2) +
coord_flip() +
geom_hline(yintercept = as.numeric(mintime), lty=2,color='red', lwd=1)+
geom_hline(yintercept = as.numeric(maxtime), lty=2,color='red', lwd=1)+
geom_rect(data=dfplot,aes(xmin=0,ymin=ymin,xmax=length(times1),ymax=ymax,fill="red"),alpha=0.2,inherit.aes=FALSE) +
theme(panel.background = element_blank(), plot.background = element_blank())
我要做的是计算times1 和times2 中每对元素之间的间隔所涵盖的时间。这些由黑色水平线和红色矩形表示。如您所见,其中一些可能重叠。实际上,我想计算两条红色虚线之间的时间比例被黑线/红色矩形覆盖,什么比例没有被覆盖(即白色间隙)。
我希望这是有道理的。
【问题讨论】:
-
我认为
data.table现在有重叠功能。对于此类问题可能会有所帮助:stackoverflow.com/questions/25815032/…
标签: r