title: how to convert a matrix of values into a binary matrix
body: <p>I'd like to convert a matrix of values into a matrix of 'bits'.</p>
  
  <p>I have been looking for solutions and found <a href="https://stackoverflow.com/questions/25271353/cleaner-way-of-constructing-binary-matrix-from-vector">this</a>, which seems to be part of a solution.
  I'll try to explain what I am looking for.
  I have a matrix like</p>
  
  <pre><code>&gt; x&lt;-matrix(1:20,5,4)
  &gt; x
       [,1] [,2] [,3] [,4]
  [1,]    1    6   11   16
  [2,]    2    7   12   17
  [3,]    3    8   13   18
  [4,]    4    9   14   19
  [5,]    5   10   15   20
  </code></pre>
  
  <p>which I would like to convert into </p>
  
  <pre><code>     1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
    1  1 0 0 0 0 1 0 0 0  0  1  0  0  0  0  1  0  0  0  0
    2  0 1 0 0 0 0 1 0 0  0  0  1  0  0  0  0  1  0  0  0
    3  0 0 1 0 0 0 0 1 0  0  0  0  1  0  0  0  0  1  0  0
    4  0 0 0 1 0 0 0 0 1  0  0  0  0  1  0  0  0  0  1  0
    5  0 0 0 0 1 0 0 0 0  1  0  0  0  0  1  0  0  0  0  1
  </code></pre>
  
  <p>so for each value in the row a "1" in the corresponding column.</p>
  
  <p>If I use </p>
  
  <pre><code>&gt; table(sequence(length(x)),t(x))
  
       1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
    1  1 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0
    2  0 0 0 0 0 1 0 0 0  0  0  0  0  0  0  0  0  0  0  0
    3  0 0 0 0 0 0 0 0 0  0  1  0  0  0  0  0  0  0  0  0
    4  0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  1  0  0  0  0
    5  0 1 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0
    6  0 0 0 0 0 0 1 0 0  0  0  0  0  0  0  0  0  0  0  0
    7  0 0 0 0 0 0 0 0 0  0  0  1  0  0  0  0  0  0  0  0
    8  0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  1  0  0  0
    9  0 0 1 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0
    10 0 0 0 0 0 0 0 1 0  0  0  0  0  0  0  0  0  0  0  0
    11 0 0 0 0 0 0 0 0 0  0  0  0  1  0  0  0  0  0  0  0
    12 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  1  0  0
    13 0 0 0 1 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0
    14 0 0 0 0 0 0 0 0 1  0  0  0  0  0  0  0  0  0  0  0
    15 0 0 0 0 0 0 0 0 0  0  0  0  0  1  0  0  0  0  0  0
    16 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  1  0
    17 0 0 0 0 1 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0
    18 0 0 0 0 0 0 0 0 0  1  0  0  0  0  0  0  0  0  0  0
    19 0 0 0 0 0 0 0 0 0  0  0  0  0  0  1  0  0  0  0  0
    20 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  1
  </code></pre>
  
  <p>this is close to what I am looking for, but returns a line for each value.</p>
  
  <p>I would only need to consolidate all values from one row into one row.
  Because a </p>
  
  <pre><code>&gt; table(x)
  x
   1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 
   1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1 
  </code></pre>
  
  <p>gives alls values of the whole table, so what do I need to do to get the values per row.</p>