Note that there are some explanatory texts on larger screens.

plurals
  1. POMatching data from 3 different data frames
    primarykey
    data
    text
    <p>I have 3 data frames as follows:</p> <pre><code>d1 &lt;- data.frame(level1 = c("A", "A", "B", "C", "C"), level2 = c("AA", "AB", "BA", "CA", "CB")) d2 &lt;- data.frame(level1 = c("A", "A", "A","B", "B", "C", "C"), level3 = c("1", "2", "4", "2", "3", "1", "5")) d3&lt;- data.frame(level3 = c("1", "2", "3", "4", "5"), AA = c("v1", "v2", "v3", "v4", "v5"), AB = c("v6", "v7", "v8", "v9", "v10"), BA = c("v11", "v12", "v13", "v14", "v15"), CA = c("v16", "v17", "v18", "v19", "v20"), CB = c("v21", "v22", "v23", "v24", "v25")) </code></pre> <p>I would like the have as output these 3 data frames:</p> <pre><code>A &lt;- data.frame(level3 = c("1", "2", "4"), AA = c("v1", "v2", "v4"), AB = c("v6", "v7", "v9")) B &lt;- data.frame(level3 = c( "2", "3"), BA = c("v12", "v13")) C &lt;- data.frame(level3 = c("1", "5"), CA = c("v16", "v20"), CB = c("v21", "25")) </code></pre> <p>From the provided 3 dataframes (d1 , d2 and d3), I would like to obatin a separate dataframe for every "Level1" (A, B, C..). </p> <p>These output dataframes should contain the columns following the d1 criteria. The rows should contain the level3 numbers that match following the criteria of d2. </p> <p>For example, </p> <p>As per d1, AA and AB match with A. So data frame A should contain these 2 columns. </p> <p>As per d2, 1,2,4 match with A, so these should be the rows in the data frame "A". </p> <p>The values of data frame "A" should be based on d3. I hope I explained myself. Thanks,</p> <p>.</p> <p>Any ideas of how this could be done?</p> <p>In my real example Level1 and Level2 nomenclatures have nothing in common.</p> <p>Thanks for your support,</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload