How to convert a list of vectors with various length into a Data.Frame?

0 votes

By using as.data.frame() is it easy if it works.

Example:

Input

d1<-list(A=c(1,2,3),B=c(4,5,6,7,8))

Output

   A B
1  1 4
2  2 5
3  3 6
4 NA 7
5 NA 8

A and B are the colnames of the data.frame.

One possible case is sapply(d1, '[', seq(max(sapply(d1, length)))), but it's also complex.

Apr 4, 2018 in Data Analytics by CodingByHeart77
• 3,680 points
78 views

1 answer to this question.

0 votes

We can easily use this command

as.data.frame(lapply(d1, "length<-",max(lengths(d1))))
answered Apr 4, 2018 by DeepCoder786
• 1,700 points

Related Questions In Data Analytics

0 votes
2 answers

how to convert a data frame into a list in R

Convert whole data frame into a list?? ...READ MORE

answered Sep 4 in Data Analytics by anonymous
• 25,820 points
21 views
0 votes
1 answer

How to convert a list to data frame in R?

Let's assume your list of lists is ...READ MORE

answered Apr 12, 2018 in Data Analytics by nirvana
• 3,060 points

edited Apr 12, 2018 by nirvana 2,515 views
0 votes
1 answer
0 votes
2 answers

How to change column names of a Data frame?

Try this way - names(data frame) <- ...READ MORE

answered Aug 26 in Data Analytics by anonymous
• 25,820 points
69 views
0 votes
2 answers

In data frame how to spilt strings into values?

You can do this using dplyr and ...READ MORE

answered Dec 4, 2018 in Data Analytics by Kalgi
• 40,440 points
48 views
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

answered Aug 21 in Data Analytics by anonymous
• 25,820 points
119 views
0 votes
1 answer

How to spilt a column of a data frame into multiple columns

it is easily achievable by using "stringr" ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,700 points
86 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,700 points
68 views