如何以指定的顺序连接字符串
试图从这个帖子对角串联字符串如何连接3个字符串,但没有成功。
我的意见是:
a<-c("a1","a2","a3")
b<-c("b1","b2","b3")
c<-c("c1","c2","c3")
我的预期产出是
"a1" "b2" "c3" "a2" "b3" "a3"
如何从上面得到上述内容
c(rbind(a,b,c))
在将较低对角线设置为丢失后,如何按行和列的派生值对向量排序
mat <- rbind(a,b,c)
mat[lower.tri(mat)] <- NA
na.omit(mat[order(col(mat) - row(mat))])
一种方法是调整Mark's
解决方案
as.vector(na.omit(c(sapply(1:3, function(i) c(a[i], b[i+1], c[i+2])))))
#[1] "a1" "b2" "c3" "a2" "b3" "a3"
也,
vec1 <- c(a,b,c)
indx <- seq(1,length(vec1), by=4)+rep(0:2,each=3)
indx1 <- indx[indx <= length(vec1)]
vec1[indx1[-length(indx1)]]
#[1] "a1" "b2" "c3" "a2" "b3" "a3"
链接地址: http://www.djcxy.com/p/4231.html