SQLDF使用R中的行ID加入

发布于 2025-02-11 11:57:43 字数 1269 浏览 1 评论 0原文

对于下表中的数据结构(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文