Skip to contents

Install Library

Load Data

data("oida_idx")

Check Object

class(oida_idx)
#> [1] "data.frame"

Convert Object

oida_idx <- tibble::as_tibble(oida_idx)
tibble::is_tibble(oida_idx)
#> [1] TRUE

Winnow

# "dt" for data tibble; note the column headings as "<list>"#
oida_idx |> 
dplyr::filter(id == c("tnmx0093", "qpnl0052", "prmx0122")) |> 
dplyr::select(id, tid, collection, collectioncode, type) -> dt
#> Warning in id == c("tnmx0093", "qpnl0052", "prmx0122"): longer object length is
#> not a multiple of shorter object length
dt
#> # A tibble: 3 × 5
#>   id       tid      collection collectioncode type     
#>   <chr>    <chr>    <list>     <list>         <list>   
#> 1 tnmx0093 txn57d00 <chr [2]>  <chr [2]>      <chr [6]>
#> 2 qpnl0052 dpl03c00 <chr [2]>  <chr [2]>      <chr [1]>
#> 3 prmx0122 ljs65e00 <chr [2]>  <chr [2]>      <chr [2]>

Rectangle Collection

dt |> 
    tidyr::unnest_longer(collection) -> dt1
dt1
#> # A tibble: 6 × 5
#>   id       tid      collection                  collectioncode type     
#>   <chr>    <chr>    <chr>                       <list>         <list>   
#> 1 tnmx0093 txn57d00 Philip Morris Records       <chr [2]>      <chr [6]>
#> 2 tnmx0093 txn57d00 Master Settlement Agreement <chr [2]>      <chr [6]>
#> 3 qpnl0052 dpl03c00 RJ Reynolds Records         <chr [2]>      <chr [1]>
#> 4 qpnl0052 dpl03c00 Master Settlement Agreement <chr [2]>      <chr [1]>
#> 5 prmx0122 ljs65e00 Philip Morris Records       <chr [2]>      <chr [2]>
#> 6 prmx0122 ljs65e00 Master Settlement Agreement <chr [2]>      <chr [2]>

Rectangle Collection Code

dt1 |> 
    tidyr::unnest_longer(collectioncode) -> dt2
dt2
#> # A tibble: 12 × 5
#>    id       tid      collection                  collectioncode type     
#>    <chr>    <chr>    <chr>                       <chr>          <list>   
#>  1 tnmx0093 txn57d00 Philip Morris Records       pm             <chr [6]>
#>  2 tnmx0093 txn57d00 Philip Morris Records       msa            <chr [6]>
#>  3 tnmx0093 txn57d00 Master Settlement Agreement pm             <chr [6]>
#>  4 tnmx0093 txn57d00 Master Settlement Agreement msa            <chr [6]>
#>  5 qpnl0052 dpl03c00 RJ Reynolds Records         rj             <chr [1]>
#>  6 qpnl0052 dpl03c00 RJ Reynolds Records         msa            <chr [1]>
#>  7 qpnl0052 dpl03c00 Master Settlement Agreement rj             <chr [1]>
#>  8 qpnl0052 dpl03c00 Master Settlement Agreement msa            <chr [1]>
#>  9 prmx0122 ljs65e00 Philip Morris Records       pm             <chr [2]>
#> 10 prmx0122 ljs65e00 Philip Morris Records       msa            <chr [2]>
#> 11 prmx0122 ljs65e00 Master Settlement Agreement pm             <chr [2]>
#> 12 prmx0122 ljs65e00 Master Settlement Agreement msa            <chr [2]>

Rectangle Type

dt2 |> 
    tidyr::unnest_longer(type) -> dt3
dt3
#> # A tibble: 36 × 5
#>    id       tid      collection            collectioncode type                  
#>    <chr>    <chr>    <chr>                 <chr>          <chr>                 
#>  1 tnmx0093 txn57d00 Philip Morris Records pm             bibliography          
#>  2 tnmx0093 txn57d00 Philip Morris Records pm             chart                 
#>  3 tnmx0093 txn57d00 Philip Morris Records pm             graph                 
#>  4 tnmx0093 txn57d00 Philip Morris Records pm             map                   
#>  5 tnmx0093 txn57d00 Philip Morris Records pm             publication, scientif…
#>  6 tnmx0093 txn57d00 Philip Morris Records pm             table                 
#>  7 tnmx0093 txn57d00 Philip Morris Records msa            bibliography          
#>  8 tnmx0093 txn57d00 Philip Morris Records msa            chart                 
#>  9 tnmx0093 txn57d00 Philip Morris Records msa            graph                 
#> 10 tnmx0093 txn57d00 Philip Morris Records msa            map                   
#> # … with 26 more rows