Q
更快%
21
A
回答
27
看的%in%
定义:
R> `%in%`
function (x, table)
match(x, table, nomatch = 0L) > 0L
<bytecode: 0x1fab7a8>
<environment: namespace:base>
可以很容易地编写自己的%fin%
功能:
`%fin%` <- function(x, table) {
stopifnot(require(fastmatch))
fmatch(x, table, nomatch = 0L) > 0L
}
system.time(for(i in 1:100) a <- x %in% table)
# user system elapsed
# 1.780 0.000 1.782
system.time(for(i in 1:100) b <- x %fin% table)
# user system elapsed
# 0.052 0.000 0.054
identical(a, b)
# [1] TRUE
3
比赛几乎总是更好地把两个向量dataframes和合并完成(见来自dplyr的各种连接)
例如,像这样的东西会给你所有你需要的信息:
library(dplyr)
data = data_frame(data.ID = 1L:100000L,
data.extra = 1:2)
sample =
data %>%
sample_n(10000, replace=TRUE) %>%
mutate(sample.ID = 1:n(),
sample.extra = 3:4)
# join table not strictly necessary in this case
# but necessary in many-to-many matches
data__sample = inner_join(data, sample)
#check whether a data.ID made it into sample
data__sample %>% filter(data.ID == 1)
或left_join,right_join,FULL_JOIN,semi_join,anti_join,根据什么信息是最有用的,你
相关问题
- 1. 更快块快递
- 2. 让Haskell代码更快更快
- 3. JavaScript settimeout继续走得更快,更快?
- 4. 坐标系更快/更快RCNN
- 5. peakpowerforchannel更新更快
- 6. Mysql更快更新
- 7. 更快更换JQuery.load()?
- 8. 日食 - 更快
- 9. 哪个更快?
- 10. 哪个更快?
- 11. 。哪个更快?
- 12. 哪个更快?
- 13. 使localhost更快?
- 14. 比xlib更快
- 15. discoverAllContactUserInfosWithCompletionHandler更快?
- 16. 让它更快?
- 17. 比GetPixel()更快?
- 18. 比in_array更快?
- 19. 更快的UIWebView?
- 20. 更快加速
- 21. 哪个更快?
- 22. QGLWidget - 更快grabFrameBuffer
- 23. 比rand()更快?
- 24. 更快Log2Ceil
- 25. 更快秀
- 26. 使sqlite3列更新更快
- 27. aoColumnDefs vs fnRowCallback更好更快
- 28. 更快的更新查询
- 29. 如何更快更换agrep?
- 30. 数据库更新更快?
但fastmatch如果你对阵NA这是行不通的,基础的比赛一样。 – skan
它在哪里?是“https://github.com/s-u/fastmatch”正确的链接?似乎很久以前不会更新。 – skan
我一直在尝试%fin%和fmatch与lapply匹配大data.frame或data.table的每一列,并且无法注意到速度上的很大差异。 – skan