title: How can you get the number of times an element appears in another column within a range?
body: <p>I want to know how often an element from one column appears in another</p>
  
  <p>Let's say I have two columns.  In these columns, I have a series of times (in milliseconds).  One column represents a gold standard (method 2) and the novel method (method 1).  I would like to create a function in which I can read any csv with 2 columns (method1 and method2) and I want it to count the frequency that the times from method1 appear in method 2.  Furthermore, because we are dealing with milliseconds, I would like to have a very small degree of tolerance i.e. if its 0.005 milliseconds, I want it to count +/- 0.002 as well (so it counts from 0.003 to 0.007).</p>
  
  <p>My end point is to output a csv that adds a 3rd column that shows the frequency of times from method1 appearing in method2.</p>
  
  <p>I have tried the following code:</p>
  
  <pre class="lang-r prettyprint-override"><code>df&lt;-read.csv("/Users/user/Desktop/R_workingdir/test__test.csv")
  
  method1&lt;-df$method1
  method2&lt;-df$method2
  
  method1&lt;-toString(method1)
  method2&lt;-toString(method2)
  
  summarise(group_by(df,method1,method2),count =n())
  </code></pre>
  
  <p>...But it only counts the frequency in the same column:</p>
  
  <p><img src="https://i.stack.imgur.com/S9zvg.png" alt="Please find attached the image of the expected input, output and what I am currently getting"></p>
  
  <p>PS. I am new to RStudio so it would be great if you can provide a short explanation of the code so I could understand.</p>