Search code examples
rlistdataframerbindcbind

Using rbind()/cbind() to append single row data in R


I have 6 numeric lists each containing different number of values i.e [1:350] , [1:450] .... . I am trying to append all of these lists into a singular list i.e [1:1050] using rbind(), but the output I get is dataframe of [1:350, 1:6].

Can someone please help me with this.


Solution

  • To concatenate multiple lists, you can use c()

    x <- list(1, 2:5)
    y <- list("A", "B")
    z <- list(letters[1:5])
    c(x, y, z)
    # [[1]]
    # [1] 1
    #
    # [[2]]
    # [1] 2 3 4 5
    #
    # [[3]]
    # [1] "A"
    #
    # [[4]]
    # [1] "B"
    #
    # [[5]]
    # [1] "a" "b" "c" "d" "e"