title: Meaning of this statement in R (Naive Bayes Classifier)
body: <p>I am going through the code that our professor has provided us with, for creating a Naive Bayes Classifier.  Note that we are not using some built-in package; rather writing it ourselves for learning purposes.</p>
  
  <p>One of the statements that the professor has used confuses me:</p>
  
  <pre><code>t = (Xtrain[,11] == c);
  </code></pre>
  
  <p>where <code>Xtrain</code> is the data set we are using to construct the classifier from.  I guess I understand what <code>Xtrain[,11] == c</code> does, but what I don't get is the assignment to <code>t</code>.  Could some one please let me know what it does and why?</p>
  
  <p>Edit:</p>
  
  <p>Following is the code that he is using to train the classifier:</p>
  
  <pre><code>X = read.csv("naive_bayes_binary.csv");
  tnum = nrow(X)/2;  
  Xtrain = X[1:tnum,];  # the data we construct the classifier from
  p = matrix(0,3,10);  #  p[c,j] = P(x_j = 1 | Y = c)
  prior = rep(0,3);  # will be prior probs
  n = rep(0,3);  # will be class counts
  for (c in 1:3) {
      t = (Xtrain[,11] == c);    ### What is this?
      n[c] = sum(t);
      for (j in 1:10) {
          p[c,j] = sum(Xtrain[t,j] == 1)/n[c]  
      # empirical prob that jth feat = 1 for cth class
      }
  }
  prior = n/tnum;  # the prior probabilities of the classes
  </code></pre>