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
32 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
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,040 points

edited Apr 12, 2018 by nirvana 1,311 views
0 votes
1 answer
0 votes
1 answer

How to change column names of a Data frame?

Easiest way: names(prices)[1]<-paste0("old") names(prices)[2]<-paste0("new") names(prices)[3]<-paste0("best") #or by using colnames colnames(prices)<-c("old","new","best") prices old ...READ MORE

answered Apr 11, 2018 in Data Analytics by DeepCoder786
• 1,700 points
24 views
0 votes
1 answer
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
• 35,800 points
23 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to sort a data frame by columns in R?

You can just use the order function ...READ MORE

answered Apr 10, 2018 in Data Analytics by darklord
• 6,140 points
53 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
23 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
32 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.