Skip to main content
  1. About
  2. For Teams
Asked
Viewed 451 times
Part of R Language Collective
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, ...).

1
  • 1
    The example list you provided is not nested
    Sotos
    –  Sotos
    2017-10-27 09:21:15 +00:00
    Commented Oct 27, 2017 at 9:21

2 Answers 2

1

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

as.data.frame(do.call(rbind, A))
Sign up to request clarification or add additional context in comments.

Comments

1

You can also unlist A.

as.data.frame(matrix(unlist(A), ncol = 2, byrow = TRUE))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.