R 高效查找 DataFrame 列中的值

发布于 2024-12-19 13:01:57 字数 220 浏览 4 评论 0原文

我有一个大型 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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一念一轮回 2024-12-26 13:01:57

我意识到这是一个老问题。只是想为那些在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文