Search code examples
rdataframedata-manipulationdata-management

how to combine two dataframes in two different lists having same names into a single list with dataframes using R


I have a list with a set of dataframes called 'a' and the structure is as shown in the following picture

enter image description here

I have another list with a set of dataframes called 'b' and having the same names as in 'a' and the structure is as shown in the following picture

enter image description here

i would like to combine the two dataframes in two lists as per their names into one list with dataframes.

for this, I am using the following code

c <-  Map(cbind, a, b)

but, the code is not working as it is giving the following output

enter image description here

the expected output will look very similar to as shown in the following picture

enter image description here

for instance in a list of length 49, a dataframe with 241 rows and 14 columns

I don't know what is the issue with the code...... looking to solve this problem I have tried all the options avalibale in stactoverflow to solve the problem


Solution

  • the problem is with the structure of the two dataframes are different and the problem is solved by converting the structure of two lists into the same structure.

    i have converted the structure of list 'b' into tibble as

    b <- tibble::as_tibble(b)
    

    then we can use the code as following

    c <-  Map(cbind, a, b)
    

    this has worked solved my problem