Hey Guys Getting spinned about a slick way to join every 2 entry in a list / vector in R x=(rep(c('A','G','C','T'),1000)) A G C T A G C T etc form another list with entries as AG CT AG etc so join the first 2 and so on. Thanks!' '-Abhi [[alternative HTML version deleted]]
On Thu, Apr 4, 2013 at 7:46 PM, Abhishek Pratap <abhishek.vit at gmail.com> wrote:> Hey Guys > > Getting spinned about a slick way to join every 2 entry in a list / vector > in R > > x=(rep(c('A','G','C','T'),1000)) > > A G C T A G C T etc > > form another list with entries as > AG CT AG etcNot super slick but: by_two <- function(x, collapse = ""){ dim(x) <- c(length(x) / 2, 2) apply(x, 1, function(y) paste(y, collapse = collapse)) } Cheers, MW