Grouping vectors by characters

I have a list of character vectors:
x_1 <- c("11_m", "11_t", "12_m", "12_t", "13_m", "13_t")
And I wish to modify it in a way that they are grouped into a new vector based on their first two characters, like so:
c(("11_m", "11_t"), ("12_m", "12_t"), ("13_m", "13_t"))

There simply is no such thing as a nested vector. But you could have a nested list

x_1 <- c("11_m", "11_t", "12_m", "12_t", "13_m", "13_t")
(x_2 <- split(x_1,substr(x_1,1,3)))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.