在 R 中生成列表的所有不同排列

编程入门 行业动态 更新时间:2024-10-28 14:24:24
本文介绍了在 R 中生成列表的所有不同排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试创建一个列表的排列列表,例如, perms(list("a", "b", "c")) 返回

I'm trying to create a list of permutations of a list, such that, for example, perms(list("a", "b", "c")) returns

list(list("a", "b", "c"), list("a", "c", "b"), list("b", "a", "c"), list("b", "c", "a"), list("c", "a", "b"), list("c", "b", "a"))

我不确定如何进行,任何帮助将不胜感激.

I'm not sure how to proceed, any help would be greatly appreciated.

推荐答案

combinat::permn 将完成这项工作:

> library(combinat) > permn(letters[1:3]) [[1]] [1] "a" "b" "c" [[2]] [1] "a" "c" "b" [[3]] [1] "c" "a" "b" [[4]] [1] "c" "b" "a" [[5]] [1] "b" "c" "a" [[6]] [1] "b" "a" "c"

请注意,如果元素很大,则计算量很大.

Note that calculation is huge if the element is large.

更多推荐

在 R 中生成列表的所有不同排列

本文发布于:2023-11-30 00:21:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648098.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:排列   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!