B. Davis
B. Davis

Reputation: 3441

Make a data frame from a list of sequences

With a list of sequences, for example,

datList <- list(One = seq(1,5, length.out = 20),
                Two = seq(1,10, length.out = 20),
                Three = seq(5,50, length.out = 20))

Is it possible to make a data frame so that the sequences are converted into columns. As in,

datDF <- data.frame(One = datList[[1]], Two = datList[[2]], Three = datList[[3]] )

> head(datDF)
       One      Two     Three
1 1.000000 1.000000  5.000000
2 1.210526 1.473684  7.368421
3 1.421053 1.947368  9.736842
4 1.631579 2.421053 12.105263
5 1.842105 2.894737 14.473684
6 2.052632 3.368421 16.842105

Within the context of my 'real' data I am working with many sequences and was hoping an apply (or similar) function could be used rather than manually creating the desired data frame.

Upvotes: 1

Views: 214

Answers (1)

akrun
akrun

Reputation: 887501

We can use data.frame

datDFN <- data.frame(datList)
identical(datDF, datDFN)
#[1] TRUE

Upvotes: 1

Related Questions