Combine lists R RisMed different length
Asked Answered
T

1

1

I gathered different lists from the RISMed package and would like to know how to combine to lists of different lengths and then transform them into a data frame.

List #1 with Authors' names:

[[1]] - First element of the list
  LastName  ForeName Initials order
1    Ellis   Peter M       PM     1
2    Verma     Sunil        S     2
3   Sehdev   Sandeep        S     3
4   Younus    Jawaid        J     4
5   Leighl Natasha B       NB     5

List #2 with PubMed IDs

[[1]] - First element of the list
27998745

I managed to compile all the authors into one dataset through the ldply function of the plyr package. However, I would like to merge it with the PubMed IDs. Exemple below:

  LastName  ForeName Initials order   PubMedID
1    Ellis   Peter M       PM     1   27998745
2    Verma     Sunil        S     2   27998745
3   Sehdev   Sandeep        S     3   27998745
4   Younus    Jawaid        J     4   27998745
5   Leighl Natasha B       NB     5   27998745

That being done for all the ~5000 IDs I have.

Thanks a lot,

Romain

EDIT: This works fine but for one article at a time. Result<- cbind(List1[[2]],PubMedID= List2[[2]])

The mapply function does not work as it puts different lists (e.g. forenames) into different variables. The PubMedID got into a row but not listed.

Teplica answered 1/8, 2013 at 17:10 Comment(2)
Your list #2 contains only the PubMed IDs?Lebanon
Yes, you are correct. This is kind of a join between two tables "by" the list indice.Teplica
L
0

It sounds like you just want to cbind the two parts together.

mapply(cbind, list1, PubMedID=list2)

This successively cbinds the corresponding elements of the two lists, producing a list of data frames. If you then want to put them into one big data frame:

rbind.fill(mapply(cbind, list1, PubMedID=list2))
Lebanon answered 1/8, 2013 at 17:59 Comment(1)
mapply(cbind, list1, PubMedID=list2) produces a matrix of lists 5 x 3 (if I use three articles).Teplica

© 2022 - 2024 — McMap. All rights reserved.