This function converts a single data frame that has subentity-level list columns in it into multiple data frames, one for each entity/subentity. The multiple data frames can be merged together using the primary key variable specified by the user (see the relational data chapter in "R for Data Science" for an in-depth introduction to joining tabular data).
unnest_pv_data(data, pk = get_ok_pk(names(data)))
data | The data returned by |
---|---|
pk | The column/field name that will link the data frames together. This
should be the unique identifier for the primary entity. For example, if you
used the patents endpoint in your call to |
A list with multiple data frames, one for each entity/subentity.
Each data frame will have the pk
column in it, so you can link the
tables together as needed.
fields <- c("patent_id", "patent_title", "inventor_city", "inventor_country") res <- search_pv(query = '{"_gte":{"patent_year":2015}}', fields = fields) unnest_pv_data(data = res$data, pk = "patent_id")#> List of 2 #> $ inventors:'data.frame': 54 obs. of 3 variables: #> ..$ patent_id : chr [1:54] "8925112" ... #> ..$ inventor_city : chr [1:54] "Thornton" ... #> ..$ inventor_country: chr [1:54] "AU" ... #> $ patents :'data.frame': 25 obs. of 2 variables: #> ..$ patent_id : chr [1:25] "8925112" ... #> ..$ patent_title: chr [1:25] "Aircrew ensembles" ...