I have some data that looks like this:
    x    y
1:  3    1
2:  6    1
3:  1    0
4: 31    8
5:  1    0
---
(Edit: if it helps, here are sample vectors for x and y
    x = c(3, 6, 1, 31, 1, 18, 73, 29, 2, 1)
    y = c(1, 1, 0, 8, 0, 0, 8, 1, 0, 0)
The column on the left (x) is my sample size, and the column on the right (y) is the number successes that occur in each sample.
I would like to fit these data using a binomial distribution in order to find the probability of a success (p). All examples for fitting a binomial distribution that I've found so far assume a constant sample size (n) across all data points, but here I have varying sample sizes.
- How do I fit data like these, with varying sample sizes, to a binomial distribution? The desired outcome is p, the probability of observing a success in a sample size of 1. 
- How do I accomplish a fit like this using R? 
(Edit #2: Response below outlines solution and related R code if I assume that the events observed in each sample can be assumed to be independent, in addition to assuming that the samples themselves are also independent. This works for my data - thanks!)
 
     
    