R 高效查找 DataFrame 列中的值
我有一个大型 R 数据框,需要根据两列 $start 和 $end 多次有效地查找行。我认为典型的解决方案是 O(N):
data[data$start <= start & data$end >= end, 1]
我更愿意对至少一列进行排序并进行更有效的 O(log(N)) 查找。存在哪些内置 R 方法可以利用数据帧中的排序进行查找?
I have a large R dataframe on which I need to look up rows based on two columns $start and $end efficiently many times. I imagine that the typical solution is O(N):
data[data$start <= start & data$end >= end, 1]
I would prefer to sort at least one of the columns and do more efficient O(log(N)) lookups. What inbuilt R methods exist to take advantage of ordering in a dataframe for lookup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我意识到这是一个老问题。只是想为那些在 R 中搜索快速查找的人提供一个链接。
R 中的查找性能 - Joseph Adler。我发现它非常全面地满足我的需求。他提倡使用双括号表示法(
[[
),并提供多种替代方案的时间比较。I realize that this is an old question. Just wanted to provide a link for those who come searching for fast lookups in R.
Lookup performance in R - Joseph Adler. I find it to be quite comprehensive for my needs. He advocates the double bracket notation (
[[
) and provides time comparisons for multiple alternatives.