[R] creating a dataframe with full_join and looping over a list of lists

Matthew mccorm@ck @end|ng |rom mo|b|o@mgh@h@rv@rd@edu
Thu Mar 21 21:58:04 CET 2019


I have been trying create a dataframe by looping through a list of lists,

and using dplyr's full_join so as to keep common elements on the same row.

But, I have a couple of problems.

1) The lists have different numbers of elements.

2) In the final dataframe, I would like the column names to be the names 
of the lists.

Is it possible ?


  for(j in avector){

     mydf3 <- data.frame(myenter)           # Start out with a list, 
myenter, to dataframe. mydf3 now has 1 column.
                                                               # This 
first column will be the longest column in the final mydf3.
     atglsts <- as.data.frame(comatgs[j])  # Loop through a list of 
lists, comatgs, and with each loop a particular list
                                                               # is made 
into a dataframe of one column, atglsts.
                                                                # The 
name of the column is the name of the list.
                                                               # Each 
atglsts dataframe has a different number of elements.
     mydf3 <- full_join(mydf3, atglsts)     # What I want to do, is to 
add the newly made dataframe, atglsts, as a
                    }                                         # new 
column of the data frame, mydf3 using full_join
                                                              # in order 
to keep common elements on the same row.
                                                              # I could 
rename the colname to 'AGI' so that I can join by 'AGI',
                                                              # but then 
I would lose the name of the list.
                                                             # In the 
final dataframe, I want to know the name of the original list

                     # the column was made from.

Matthew



	[[alternative HTML version deleted]]



More information about the R-help mailing list