如何查看一个向量中的值是否位于另一向量中的任意两个值之间
我有两个日期时间格式的向量,我想知道向量 A 中的任何日期时间戳是否落在向量 B 中的两个给定日期时间戳之间。
data <- tibble(
Col_A = structure(c(1514935860, 1514936280, 1514946120, 1515090600, 1515090600, 1515095040), tzone = "UTC", class = c("POSIXct", "POSIXt")),
Col_B = structure(c(1517564040, 1517564340, 1517564640, 1517564940, 1517565240, 1517565540), tzone = "UTC", class = c("POSIXct", "POSIXt"))
我已经尝试过此操作,
check <- data$Col_A
data$dummy <- ifelse(data$Col_B %in% check, "1", "0")
但这仅返回Col_A 中的数据点在 Col_B 的整个范围内,但我需要代码来检查 Col_B 中两个日期时间戳的每个间隔。
I have two vectors in date time format, and I would like to know if any of the date time stamps in vector A fall in between any of the two given date time stamps in vector B.
data <- tibble(
Col_A = structure(c(1514935860, 1514936280, 1514946120, 1515090600, 1515090600, 1515095040), tzone = "UTC", class = c("POSIXct", "POSIXt")),
Col_B = structure(c(1517564040, 1517564340, 1517564640, 1517564940, 1517565240, 1517565540), tzone = "UTC", class = c("POSIXct", "POSIXt"))
I have tried this,
check <- data$Col_A
data$dummy <- ifelse(data$Col_B %in% check, "1", "0")
but this only returns the data points in Col_A within the entire range of Col_B, but I need the code to check every interval of two date time stamps in Col_B.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我们需要对任何组合、
数据执行此操作
If we need to do this on
any
combination,data