I have the following vector Vec
:
ACGTTGCA
and would like to divide it into a nested vector, in which on the i-ith positions there will be a subsegment of Vec
of length 4, starting at the i-th position of Vec
.
For example, Vec[(⍳¯3+⍴Vec)∘.+¯1+⍳4]
returns:
ACGT
CGTT
GTTG
TTGC
TGCA
But the problem with the above output is that it is a character matrix, whereas I would like to get the following output:
┌──────────────────────────┐
│┌────┬────┬────┬────┬────┐│
││ACGT│CGTT│GTTG│TTGC│TGCA││
│└────┴────┴────┴────┴────┘│
└──────────────────────────┘
For the following string:
vec←'Hy, only testing segmenting vec into pieces of 4'
the correct result of what I'm looking for would be:
┌→────────────────────────────────────────┐
│ ┌→───┐ ┌→───┐ ┌→───┐ ┌→───┐ │
│ │Hy, │ │y, o│ │, on│ │ onl│ (and so on) │
│ └────┘ └────┘ └────┘ └────┘ │
└∊────────────────────────────────────────┘
Also, is there a way to convert such vector to a single vector, in which subsequent lines would contain 4 characters?
Example: for a foobartesting
character vector the result would be:
foob
ooba
obar
bart
arte
rtes
test
esti
stin
ting