Assign 1 in a matrix from a list of coordinates
<p>I want to take a list of coordinates. For every location in the coordinates, I want to assign 1 to the matrix.  The final matrix should look like this.  I want to use a fast vectorized method instead of a for loop.</p>

<pre><code>    &gt; sample.matrix
      A B C D E F G H I J K L M N O P Q R S T
    A 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    B 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
    C 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    D 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
    E 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    F 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
    G 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    H 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
    I 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    J 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
    K 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    L 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    M 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
    N 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
    O 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
    P 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
    Q 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
    R 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
    S 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    T 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
</code></pre>

<p>Sample data:</p>

<pre><code>    set.seed(15)
    dat &lt;- data.frame(x=sample(LETTERS[1:20], 15,set.seed(15)),y=sample(LETTERS[1:20], 15,set.seed(15)), stringsAsFactors = FALSE)
    sample.matrix &lt;- matrix(data=0, nrow = 20, ncol = 20, dimnames = list(LETTERS[1:20],LETTERS[1:20]))
</code></pre>

<p>What I tried that worked.</p>

<pre><code>    for ( n in 1:15){
      sample.matrix[dat[n,]$x,dat[n,]$y] =1
    }
</code></pre>

<p>What I tried that isn't working. </p>

<pre><code>by(dat, 1:15, function(a.row){sample.matrix[a.row$x, a.row$y]=1})
</code></pre>