如何使用三个向量按索引进行R嵌套循环
我正在尝试执行 3 个向量的相交。我希望 x、y、z 按照下面的预期采用值并插入到 trans.list
、prot.list
和 PT.list.
#v = number of vectors (number of sets)
V <- 3
#N= number of clusters in each set
N <- 5
intersects <- vector(length=N^V,mode='character')
for (x in 1:N) {
for (y in 1:N) {
for (z in 1:N) {
inters <- length(Reduce(intersect,
list(
trans.list[[x]][["NAME"]],
prot.list[[y]][["NAME"]],
PT.list[[z]][["NAME"]]
)
))
intersects[x, y, z] <- inters
但最后,我似乎无法将其作为值保存到索引中。有什么建议吗?
[1] "1,1,1"
[1] "1,1,2"
[1] "1,1,3"
[1] "1,1,4"
[1] "1,1,5"
[1] "1,2,1"
[1] "1,2,2"
...
I am trying to carry out the intersect of the 3 vectors. I intend the x, y ,z to take up values as intended below and be inserted to the trans.list
, prot.list
and PT.list
.
#v = number of vectors (number of sets)
V <- 3
#N= number of clusters in each set
N <- 5
intersects <- vector(length=N^V,mode='character')
for (x in 1:N) {
for (y in 1:N) {
for (z in 1:N) {
inters <- length(Reduce(intersect,
list(
trans.list[[x]][["NAME"]],
prot.list[[y]][["NAME"]],
PT.list[[z]][["NAME"]]
)
))
intersects[x, y, z] <- inters
However at the end, I cant seem to save it to index as a value. any advice?
[1] "1,1,1"
[1] "1,1,2"
[1] "1,1,3"
[1] "1,1,4"
[1] "1,1,5"
[1] "1,2,1"
[1] "1,2,2"
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论