<分区>
我知道 combn() 可以为我提供向量中的所有独特组合。但是,它给了我一个矩阵输出,我想要它作为一个向量。将输出包装在 as.vector() 中使每个值都独立,首先失去了运行 combn() 的目的。假设我的数据集是 c("a", "b", "c"),我如何使用 combn()(或其他一些函数)来获得一个向量,我的输出将是:
my_data <- c("a", "b", "c")
#natural output with combn()
#output with combn()
combn(my_data, 2, simplify = TRUE)
#output with as.vector() wrapped
as.vector(combn(my_data, 2, simplify = TRUE))
#desired output
answer <- c("ab", "ac", "bc") #I don't care about order