Search code examples
rpackagepubmed

Extract rows from dataframe inside list inside dataframe in R


I'm using package RISmed in R in order to obtain information from PubMed. The 'Mesh' package function allows me to obtain the MeSH terms of each citation. Nevertheless it is a List, containing a Data Frame. I want to list each MeSH term besides its corresponding citation id (PMID). For example, I can construct a table containing both values:

table = cbind(ArticleId(MedlineObject),Mesh(MedlineObject))

The first column is a char object but the second one is a list, containing a dataframe. If the value inside 1st column were "29145282" and the content of 2dnd column were "Cardiomyopathy, Hypertrophic", "Combined Modality Therapy" and "Diagnosis, Differential", I would want to obtain:

"29145282","Cardiomyopathy, Hypertrophic"
"29145282","Combined Modality Therapy"
"29145282","Diagnosis, Differential"

How could I accomplish this?


Solution

  • I would like to use myeloma as an example of medline object since I don't have your data. myeloma is a medline data within RISmed package.

    First add the id to all dataframes in your list by mapply and cbind:

    MedList = mapply(cbind, "ID"=ArticleId(myeloma),Mesh(myeloma),SIMPLIFY = FALSE)
    

    And then merge all list into one dataframe by do.call and rbind:

    MedFrame = do.call("rbind",MedList)
    

    You just need to change 'myeloma' in the code to your own MedlineObject