【发布时间】:2021-09-01 18:09:33
【问题描述】:
我有 dataframe1 和一个行索引向量:
dataframe1 <-data.frame(time = c(0.5, 1.5, 2.5, 3.5, 4.5, 5),
x = c("light", "light", "light", "dark", "dark", "dark"))
vector <- c(1, 3, 6)
我也有dataframe2
dataframe2 <- data.frame(time = c(0.6, 1, 1.4, 2, 2.4, 3.2, 3.5, 4, 4.5, 5))
我想使用dataframe1$time 中与vector 中的行位置相对应的值来定义dataframe2 中的边界,这样我就得到了这个数据集:
dataframe2
time x
1 0.6 light
2 1.0 light
3 1.4 light
4 2.0 light
5 2.4 light
6 3.2 dark
7 3.5 dark
8 4.0 dark
9 4.5 dark
10 5.0 dark
换句话说,我想使用vector(例如,1 & 3)和相应的dataframe1$time(例如,0.5 & 2.5)给出的行索引来查找dataframe2$time 中>= 0.5 和 =dataframe2 中创建一个新列x 对应于dataframe1$x。
我确实不想要使用 time 作为键值(例如 cbind)来组合数据集。
我希望这很清楚。提前感谢您的帮助。
【问题讨论】:
标签: r dataframe vector dplyr subset