title: Intersection of two dataframes
body: <p>I am trying to keep only the columns AND rows of two dataframes that are common to both of them. Put differently, I am trying to filter for the column names and the elements of one column (which contains the dates):</p>
  
  <p>I tried this so far (from one of the forums here):</p>
  
  <pre><code>common_cols &lt;- intersect(colnames(df_tot), colnames(roe))
  common_rows &lt;-as.Date(intersect(df_tot$dates, roe$dates), origin = "1970-01-01")
  
  df_tot[common_rows, common_cols]
  roe[common_rows, common_cols]
  </code></pre>
  
  <p>But the dataset contains only NAs. Can someone help?</p>
  
  <p>I tried a different approach, which worked now:</p>
  
  <pre><code>row.names(df_tot)&lt;-df_tot$dates
  row.names(roe)&lt;-roe$dates
  
  common_cols &lt;- intersect(colnames(df_tot), colnames(roe))
  common_rows &lt;- intersect(rownames(df_tot), rownames(roe))
  
  df_tot[common_rows, common_cols]
  roe[common_rows, common_cols]
  </code></pre>