我想知道是否有人能想出一种更快的方法来计算向量中元素的组合。我的方法有效,但在向量中有大约600万个元素,速度很慢。
测试向量
test.vector <- c("335261 344015 537633","22404 132858","254654 355860 488288","219943 373817","331839 404477")
我的方法
lapply(strsplit(test.vector, " "), function(x) unique(apply(combn(x, 2), 2, function(y) paste0(y, collapse = ""))))
期望的输出
[[1]]
[1] "335261344015" "335261537633" "344015537633"
[[2]]
[1] "22404132858"
[[3]]
[1] "254654355860" "254654488288" "355860488288"
[[4]]
[1] "219943373817"
[[5]]
[1] "331839404477"
https://stackoverflow.com/questions/50751179
复制相似问题