如何以指定顺序连接字符串 [英] How to concatenate strings in a specified order

查看:34
本文介绍了如何以指定顺序连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试通过这篇文章对角地连接字符串如何交替连接3个字符串,但未成功。

Tried to concatenate strings diagonally from this post how to alternatively concatenate 3 strings, but was not successful.

我的输入是:

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))  


推荐答案

如何对向量进行排序将下对角线设置为丢失后,由行和列得出的值

How about ordering the vector by values derived by the row and columns after setting the lower diagonal to missing

mat <- rbind(a,b,c)

mat[lower.tri(mat)] <- NA
na.omit(mat[order(col(mat) - row(mat))])

这篇关于如何以指定顺序连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆