0

I have a list that contains vectors of strings like this:

A <- list(c("A", "1"), c("G", "2"), c("T", "6"), c("A", "1"), c("A", "1"), 
          c("A", "1"), c("A", "1"), c("A", "2"), c("A", "2"), c("A", "2"), 
          c("A", "2"), c("A", "3"), c("X", "3"), c("A", "4"), c("A", "4"), 
          c("A", "4"), c("A", "5"), c("A", "5"), c("A", "2"), c("A", "6"))

I want to creat two columns in a dataframe, one with the first elements ("A", "G", ...) and one with the second element (1, 2, ...).

ulima2_
  • 1,276
  • 1
  • 13
  • 23

2 Answers2

1

We rbind the list elements with do.call and then convert the matrix to data.frame

as.data.frame(do.call(rbind, A))
akrun
  • 874,273
  • 37
  • 540
  • 662
1

You can also unlist A.

as.data.frame(matrix(unlist(A), ncol = 2, byrow = TRUE))
nghauran
  • 6,648
  • 2
  • 20
  • 29