从向量r创建所有可能的字符串
我有一个带四个字母的矢量。
letter <- c('x', 'y', 'z', 'j')
我想创建所有由20个字母组成的字符串,重复我的四个字母。
我尝试使用combn()
和随机
软件包,但我失败了。
I have a vector with four letters.
letter <- c('x', 'y', 'z', 'j')
I would like to create all possible strings composed of 20 letters, repeating my four ones.
I tried with combn()
and the random
package but I failed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您应该意识到,您的计算机可能无法握住巨大的字符串(所有20个字母的组合),例如,
如果我们的字符串较短,似乎仍然可以这样做。
以下是几个基本R选项,可以产生所有组合
,而速度基准为
First of all, you should be aware that your computer may not able to hold that huge amont of strings (all combinations of 20 letters), e.g.,
However, if we have shorter strings, it seems still possible to do that.
Here are a couple of base R options that could produce all combinations
and the speed benchmarking is