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,070
  • 11
  • 22

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
  • 789,025
  • 32
  • 460
  • 575
1

You can also unlist A.

as.data.frame(matrix(unlist(A), ncol = 2, byrow = TRUE))
nghauran
  • 6,402
  • 2
  • 18
  • 27