R - 从列表中获取每个组合,但以列表形式
我正在做的事情需要我从向量中的字符列表中获取所有可能的对组合,然后对每对的价格进行 t 检验。
我认为一个好的开始方法是使用 commn(vector, 2) 获取每一对,然后迭代每个嵌套向量以对它们执行 t 检验。不幸的是,输出不会产生具有嵌套向量的向量,而只是将它们输出到二维矩阵中。
我怎样才能使我有一个嵌套向量的向量,这样我就可以迭代每对字符而不是每个字符?
例如,我想要 [[A, B], [A, C], [A, D]...] 等等,其中对第一个项目进行子集化将产生 [A, B],再次对第一个项目进行子集化会产生[A]。
但相反,我得到 [A, B, A, C, A, D],其中对第一项进行子集化会产生 [A],对第二项进行子集化会产生 [B]。
I am working on something that requires I get every possible pair combination from a list of characters in a vector and then performing t-tests on the price of each pair.
I figured a good way to start would be to use combn(vector, 2) to get each pair and then iterate through each nested vector to perform a t-test on them. Unfortunately, the output does not produce a vector with nested vectors, and instead just outputs them out in a two-dimensional matrix.
How could I make it so that I have a vector of nested vectors so I can just iterate through each pair of characters instead of each character?
For example, I would want [[A, B], [A, C], [A, D]...] and so on, where subsetting the first item would produce [A, B], subsetting the first item again would produce [A].
But instead, I am getting [A, B, A, C, A, D], where subsetting the first item produces [A], and subsetting the second item produces [B].
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还会使用
combn
如下:I would also use
combn
as the following: