text: user4595: I have called copy number and I have 2 files (I have shared the link of my files ); One contains some ranges 
  > head(cndata[,c(2,3,4)])
       Chromosome   Start      End
  4470          1   51479   817980
  4471          1  818499  1136753
  4472          1 1138735  2558308
  4473          1 2558740  5724264
  4474          1 5724940  5749083
  4475          1 5749226 12529544
  > 
  
  https://www.dropbox.com/s/wei3i787c9nrz8q/WTSI-OESO_121_1pre.copynumber.caveman.txt.csv?dl=0
  I have another file like below 
                Chromosome         Position
  rs62635286       1                 51479   
  rs75454623       1                 114930
  rs806731         1                 30923
  
  https://www.dropbox.com/s/tiqjhkrpfr9d9gu/WTSI-OESO_121_1pre.copynumber.txt?dl=0
  In first  column I have some SNPs, how I can count the number of SNP in each range? For example based on the second table how many SNP are in range of 51479 to  817980?
  
  user57: There is like a thousand different ways how to achieve this. You could use a specialised software for this (like bedtools) or calculate it simply in R.
  R solution: You can make a function that calculates the number of SNPs in a range and than you can apply it on all the ranges in the table with genomic ranges.
  snp_table <- read.table('WTSI-OESO_121_1pre.copynumber.txt')
  genomic_ranges <- read.table('WTSI-OESO_121_1pre.copynumber.caveman.txt.csv', sep = ',', col.names = c('Chromosome', 'Start', 'End'), stringsAsFactors = F)
  
  how_many_in_range <- function(coords){
      coords = as.vector(coords)
      sum(snp_table$Chromosome == coords[1] & snp_table$Position > as.numeric(coords[2]) & snp_table$Position < as.numeric(coords[3]))
  }
  
  genomic_ranges$number_of_snps <- apply(genomic_ranges, 1, how_many_in_range)
  
  Now the table genomic_ranges has a variable that sais how many SNPs are in the range.
  
original_text: 4595: <p>I have called copy number and I have 2 files (I have shared the link of my files ); One contains some ranges </p>
  
  <pre><code>&gt; head(cndata[,c(2,3,4)])
       Chromosome   Start      End
  4470          1   51479   817980
  4471          1  818499  1136753
  4472          1 1138735  2558308
  4473          1 2558740  5724264
  4474          1 5724940  5749083
  4475          1 5749226 12529544
  &gt; 
  </code></pre>
  
  <p><a href="https://www.dropbox.com/s/wei3i787c9nrz8q/WTSI-OESO_121_1pre.copynumber.caveman.txt.csv?dl=0" rel="nofollow noreferrer">https://www.dropbox.com/s/wei3i787c9nrz8q/WTSI-OESO_121_1pre.copynumber.caveman.txt.csv?dl=0</a></p>
  
  <p>I have another file like below </p>
  
  <pre><code>              Chromosome         Position
  rs62635286       1                 51479   
  rs75454623       1                 114930
  rs806731         1                 30923
  </code></pre>
  
  <p><a href="https://www.dropbox.com/s/tiqjhkrpfr9d9gu/WTSI-OESO_121_1pre.copynumber.txt?dl=0" rel="nofollow noreferrer">https://www.dropbox.com/s/tiqjhkrpfr9d9gu/WTSI-OESO_121_1pre.copynumber.txt?dl=0</a></p>
  
  <p>In first  column I have some SNPs, how I can count the number of SNP in each range? For example based on the second table how many SNP are in range of <code>51479</code> to  <code>817980</code>?</p>
   57: <p>There is like a thousand different ways how to achieve this. You could use a specialised software for this (like bedtools) or calculate it simply in R.</p>
  
  <p>R solution: You can make a function that calculates the number of SNPs in a range and than you can apply it on all the ranges in the table with genomic ranges.</p>
  
  <pre><code>snp_table &lt;- read.table('WTSI-OESO_121_1pre.copynumber.txt')
  genomic_ranges &lt;- read.table('WTSI-OESO_121_1pre.copynumber.caveman.txt.csv', sep = ',', col.names = c('Chromosome', 'Start', 'End'), stringsAsFactors = F)
  
  how_many_in_range &lt;- function(coords){
      coords = as.vector(coords)
      sum(snp_table<span class="math-container">$Chromosome == coords[1] &amp; snp_table$</span>Position &gt; as.numeric(coords[2]) &amp; snp_table$Position &lt; as.numeric(coords[3]))
  }
  
  genomic_ranges$number_of_snps &lt;- apply(genomic_ranges, 1, how_many_in_range)
  </code></pre>
  
  <p>Now the table <code>genomic_ranges</code> has a variable that sais how many SNPs are in the range.</p>
  