A user has two lists and want to interleaf an element of two lists into one.How to do that?

466    Asked by NatashaKadam in Data Science , Asked on Dec 10, 2019
Answered by Natasha Kadam

Let us create two lists.

l1 <- list('a.1','a.2', 'a.3')

l2 <- list('b.1','b.2', 'b.3', 'b.4')

We can do the following way

index <- order(c(seq_along(l1), seq_along(l2))) unlist(c(l1,l2))[index] # [1] "a.1" "b.1" "a.2" "b.2" "a.3" "b.3" "b.4"



Your Answer

Interviews

Parent Categories