Thursday, 2 February 2017
r - How to concatenate strings in a specified order
Answer
Answer
Tried to concatenate strings diagonally from this post how to alternatively concatenate 3 strings, but was not successful.
My input is:
a<-c("a1","a2","a3")
b<-c("b1","b2","b3")
c<-c("c1","c2","c3")
My expected output would be
"a1" "b2" "c3" "a2" "b3" "a3"
How to get the above from
c(rbind(a,b,c))
Answer
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))])
Subscribe to:
Post Comments (Atom)
c++ - Does curly brackets matter for empty constructor?
Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...
-
A fair amount of the second act of The Dark Knight Rises has a class warfare plotline. This is foreshadowed in the trailers with Selina Ky...
-
How can I detect either numbers or letters in a string? I am aware you use the ASCII codes, but what functions take advantage of the...
-
I want to create an options array from a string. How can i create an array as { width : 100, height : 200 } from a string ...
No comments:
Post a Comment