Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试在 R 中编写一个程序,当给定一个向量时,它将返回该向量中所有可能的元素元组。
例如:元组(c('a','b','c')) = c('a','b','c'); 出租车'); c('a','c'), c('b','c'); c('a'); c('b'); c('c')
我认为它应该返回一个向量列表。
作为参考,这里有一个在 Stata 中执行类似功能的程序。
您可以使用combn:
combn
x <- 1:3 unlist(lapply(x, function(n) combn(x, n, simplify=FALSE)), recursive=FALSE)