title: non-numeric argument binary operator error
body: <p>Not sure why I am getting a non-numeric argument binary operator error. Do I have some type mismatch going on?</p>
  
  <pre><code>   for (j in 1:length(theta)) {
        val = exp(y * sum(theta * random_data_vector) * y * random_data_vector[i])
        val = val / (1 + exp(y * sum(theta * random_data_vector)))
        theta[j] = theta[j] - (alpha * val)
      }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Error in theta * random_data_vector : 
    non-numeric argument to binary operator
  </code></pre>
  
  <p>Values: </p>
  
  <pre><code>&gt; head(theta)
  [1]  0.02435863 -0.74310189 -0.63525839  0.56554085 -0.20599967  0.43164130
  &gt; head(random_data_vector)
  [1] 0 0 0 0 0 0
  &gt; y
      V9437
  785     1
  </code></pre>
  
  <p>After FIRST iteration of for loop, <code>theta</code> looks like this:</p>
  
  <pre><code>&gt; head(theta)
  [[1]]
  [1] NA
  
  [[2]]
  [1] -0.2368957
  
  [[3]]
  [1] 0.697332
  
  [[4]]
  [1] 0.6104201
  
  [[5]]
  [1] 0.8182983
  
  [[6]]
  [1] 0.7093492
  </code></pre>
  
  <p>For more information, the above is a snippet from my entire function I am trying to create around stochastic gradient descent.</p>
  
  <p><code>data</code> is a set of rows grabbed from a CSV
  <code>labels</code> is 1 row grabbed from a CSV
  <code>alpha</code> is a float</p>
  
  <pre><code>mnist = read.csv('mnist_train.csv', header=FALSE)
  data = mnist[,mnist[nrow(mnist),]==0 | mnist[nrow(mnist),]==1, drop=FALSE]
  labels = data[785,]
  data = data[1:784,]
  
  train = function(data, labels, alpha) {
    theta = runif(nrow(data),-1,1)
    decay_rate = .01
    random_column_indexes = sample(ncol(data))
    idx = 1
    limit = length(random_column_indexes)
    threshold = 1e-5
    delta = 1000000
  
    for (n in 1:ncol(data)) {
      if (delta &lt;= threshold) {
        break
      }
      i = random_column_indexes[n]
      random_data_vector = data[, i]
      y = labels[i]
      previous_theta = theta
      for (j in 1:length(theta)) {
        val = exp(y * sum(theta * random_data_vector) * y * random_data_vector[i])
        val = val / (1 + exp(y * sum(theta * random_data_vector)))
        theta[j] = theta[j] - (alpha * val)
      }
      alpha = alpha - decay_rate
      delta = abs(previous_theta - theta)
    }
    return(theta)
  }
  </code></pre>