我想使用系统发育树的 tree$edge 行创建一个名称向量。我怎样才能构建这个向量?例子:
tree$edge # object
[,1] [,2]
[1,] 82 83
[2,] 83 84
[3,] 84 85
[4,] 85 86
[5,] 86 87
[6,] 87 88
[7,] 88 89
[8,] 89 90
[9,] 90 91
[10,] 91 1
[11,] 91 92
[12,] 92 2
[13,] 92 93
[14,] 93 94
[15,] 94 3
[16,] 94 4
[17,] 93 95
[18,] 95 96
[19,] 96 5
[20,] 96 6
我想创建一个向量(我称之为“vector_names”),每个元素都是tree$edge的行之一。我可以逐行执行此操作:
vector_names = c(paste(tree$edge[1,1],tree$edge[1,2], sep = "_"),
paste(tree$edge[2,1],tree$edge[2,2], sep = "_"),
paste(tree$edge[3,1],tree$edge[3,2], sep = "_"),
and so on until last row ....)
结果将是:
vector_names = 82_83, 83_84, 84_85, 85_86, etc.
但是是一个有 161 行的长表,我想知道是否有更快的方法来生成上面的 vector_names。