SQLDF使用R中的行ID加入
对于下表中的数据结构(peak_refined),我想将列ID与第二个表('dat')的唯一行匹配。我更喜欢使用SQLDF软件包,但请参考ROW.NAME。在下面给出的任何指针的测试代码。理想情况下,我希望从表“ dat”的记录1和6中检索“时间”。
表peak_refined
structure(list(IDs = c(1L, 6L, 28L, 31L, 668L, 2841L, 2862L,
2865L, 2906L, 2917L, 2925L, 2957L, 2960L, 2966L, 2984L, 2993L,
3000L)), class = "data.frame", row.names = c("X1", "X2", "X3",
"X4", "X5", "X6", "X7", "X8", "X9", "X10", "X11", "X12", "X13",
"X14", "X15", "X16", "X17"))
表dat:
structure(list(Time=c("2021-06-18 12:36:00", "2021-06-18 12:38:00", "2021-06-18 12:40:00",
“ 2021-06-18 12:42:00”,“ 2021-06-18 12:44:00”,“ 2021-06-- 18 12:46:00“, “ 2021-06-18 12:48:00”,“ 2021-06-18 12:50:00”,“ 2021-06-18 12:52:00”, “ 2021-06-18 12:54:00”))))
[1] "2021-06-18 12:36:00" "2021-06-18 12:38:00" "2021-06-18 12:40:00"
[4] "2021-06-18 12:42:00" "2021-06-18 12:44:00" "2021-06-18 12:46:00"
[7] "2021-06-18 12:48:00" "2021-06-18 12:50:00" "2021-06-18 12:52:00"
[10] "2021-06-18 12:54:00"
测试的代码:
library(sqldf)
sq <- sqldf("SELECT peak_refined.IDs, dat.row.names
FROM peak_refined
INNER JOIN dat
ON peak_refined.IDs = dat.row.names")
For the data structure in the table below (peak_refined) I'd like to match the column ID with the unique row.names of the second table ('dat'). I'd prefer to use the sqldf package but stuck with referencing the row.name. Tested code given below for any pointers. Ideally I expect to retrieve the 'Time' from records 1 and 6 of table 'dat'.
Table peak_refined
structure(list(IDs = c(1L, 6L, 28L, 31L, 668L, 2841L, 2862L,
2865L, 2906L, 2917L, 2925L, 2957L, 2960L, 2966L, 2984L, 2993L,
3000L)), class = "data.frame", row.names = c("X1", "X2", "X3",
"X4", "X5", "X6", "X7", "X8", "X9", "X10", "X11", "X12", "X13",
"X14", "X15", "X16", "X17"))
Table Dat:
structure(list(Time=c("2021-06-18 12:36:00", "2021-06-18 12:38:00", "2021-06-18 12:40:00",
"2021-06-18 12:42:00", "2021-06-18 12:44:00", "2021-06-18 12:46:00",
"2021-06-18 12:48:00", "2021-06-18 12:50:00", "2021-06-18 12:52:00",
"2021-06-18 12:54:00")))
[1] "2021-06-18 12:36:00" "2021-06-18 12:38:00" "2021-06-18 12:40:00"
[4] "2021-06-18 12:42:00" "2021-06-18 12:44:00" "2021-06-18 12:46:00"
[7] "2021-06-18 12:48:00" "2021-06-18 12:50:00" "2021-06-18 12:52:00"
[10] "2021-06-18 12:54:00"
Tested Code:
library(sqldf)
sq <- sqldf("SELECT peak_refined.IDs, dat.row.names
FROM peak_refined
INNER JOIN dat
ON peak_refined.IDs = dat.row.names")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论