gpt4 book ai didi

r - 取消列出两列,同时保留列中的值对

转载 作者:行者123 更新时间:2023-12-04 11:56:13 26 4
gpt4 key购买 nike

我试图取消列出一个列表以获得一个排序的(这是点)数组,但我找不到任何提示。

所以,让我们说这是我的 list :

V1<-c("Node 1","Node 3","Node 3","Node 3","Node 4","Node 4","Node 4","Node 4","Node 5","Node 7","Node 8","Node 8");
V2<-c("Node 2","Node 5","Node 6","Node 2","Node 1","Node 5","Node 7","Node 2","Node 2","Node 8","Node 6","Node 3");
try<-data.frame(V1,V2);
colnames(try)<-c("V1","V2");

现在,如果我尝试取消列出它,这就是我得到的:
array(unlist(try))
[1] "Node 1" "Node 3" "Node 3" "Node 3" "Node 4" "Node 4" "Node 4" "Node 4"
[9] "Node 5" "Node 7" "Node 8" "Node 8" "Node 2" "Node 5" "Node 6" "Node 2"
[17] "Node 1" "Node 5" "Node 7" "Node 2" "Node 2" "Node 8" "Node 6" "Node 3"

但这不是我想要的。我需要一个保留两列耦合的数组。假设我需要将 V1 的第一个值与 V2 的第一个值,然后是来自 V1 的第二个值和来自 V2 的第二个值等......并最终将它们放在一个数组中:
"Node 1","Node 2","Node 3","Node 5","Node 3","Node 6","Node 3","Node 2","Node 4","Node 1","Node 4","Node 5","Node 4","Node 7","Node 4","Node 2","Node 5","Node 2","Node 7","Node 8","Node 8","Node 6","Node 8","Node 3"

谁有不使用 for 循环的解决方案?或者这是唯一的方法?

最佳答案

更短:

c(t(try))
[1] "Node 1" "Node 2" "Node 3" "Node 5" "Node 3" "Node 6" "Node 3" "Node 2" "Node 4" "Node 1" "Node 4" "Node 5"
[13] "Node 4" "Node 7" "Node 4" "Node 2" "Node 5" "Node 2" "Node 7" "Node 8" "Node 8" "Node 6" "Node 8" "Node 3"

关于r - 取消列出两列,同时保留列中的值对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37025281/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com