我在R
中有两个列表 1)a<-as.list(c(2,4,6,10))
int : 2
int : 4
int : 6
int : 10
2)b<-as.list(c("a","b","c","d","e","f","g","h","i","j","k","l","m"))
chr : "a"
chr : "b"
chr : "c"
chr : "d"
chr : "e"
chr : "f"
chr : "g"
chr : "h"
chr : "i"
chr : "j"
chr : "k"
chr : "l"
chr : "m"
我需要一个输出,其间隔来自列表1 2:4,6:10
b c d f g h i j
答案 0 :(得分:1)
见这个
a <- list(2,4,6,10)
b <- lapply(1:13,function(x) letters[x])
M <- matrix(unlist(a),byrow = T,ncol=2)
unlist(b)[unlist(mapply(seq,M[,1],M[,2]))]
感谢@ Psidom的评论,我们可以使用
b[unlist(Map(seq, a[c(T, F)], a[c(F, T)]))]
而不是
M <- matrix(unlist(a),byrow = T,ncol=2)
unlist(b)[unlist(mapply(seq,M[,1],M[,2]))]