r - 如何在R中的向量中找到唯一的数字对?
问题描述
让我们假设C<-c(1,2,3,4,5)
我想找到可以从该向量中提取的所有唯一数字对,例如 12,13 23 等。我该怎么做?
解决方案
使用RcppAlgos
包。
## Combinations
unlist(RcppAlgos::comboGeneral(x, 2, FUN=function(x) Reduce(paste0, x)))
# [1] "12" "13" "14" "15" "23" "24" "25" "34" "35" "45"
## Permutations
unlist(RcppAlgos::permuteGeneral(x, 2, FUN=function(x) Reduce(paste0, x)))
# [1] "12" "13" "14" "15" "21" "23" "24" "25" "31" "32" "34" "35" "41" "42" "43"
# [16] "45" "51" "52" "53" "54"
推荐阅读
- ruby - 有没有办法将文件夹包含在生产构建中但没有 jekyll 编译它?
- bash - 在 BASH 中同时运行两个 xterm 命令
- c# - WebClient 收到的字节数多于 TotalBytesToReceive
- web-deployment - 在 plesk 网络主机上部署 Nuxt.js 项目?
- python - 如何解决“方法 col([class java.util.ArrayList]) 不存在”
- python-3.x - Python 简单的用户名/密码和字典
- linux - SSL 请求在 WSL 上失败
- java - 类包含子类的一个元素
- botframework - 如何将 AdaptiveCards 与基于 LUIS 的 Azure WebApp Bot (Microsoft BotFramework) C# 结合使用
- azure - Azure Functions v2 - 新的 .netcore 配置和部署