Saturday 21 October 2017

r - How to concatenate strings in a specified order

itemprop="text">

Tried to concatenate strings
diagonally from this post href="https://stackoverflow.com/questions/24346355/how-to-alternatively-concatenate-3-strings">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))



class="post-text" itemprop="text">
class="normal">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))])

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...