title: Error in model frame with variable length in R
body: <p>Today is my first day using R and I am having a problem which I could not find a solution to. 
  I want to use decision tree on a data and I'm using this command:</p>
  
  <pre><code>library(tree)
  options("na.action")
  setwd('C:/Users/aanam/Documents/Amrita_internship') pschool =
  read.csv('predict_school_new.csv', header = TRUE)
  
  stree = pschool[,c(2,4,6,8,10)]
  train = sample(1:nrow(stree),nrow(stree)/2)
  test = -train
  
  training_data = stree[train,]
  testing_data = stree[test,] 
  campus = stree[,1]
  
  testing_campus = campus[test]
  tree_model = tree(campus~.,data = training_data, na.action = "na.exclude")
  </code></pre>
  
  <p>The error that I'm getting is -</p>
  
  <pre><code>tree_model = tree(campus~.,data = training_data, na.action = "na.exclude")
  # Error in model.frame.default(formula = campus ~ ., data = training_data,  : 
  #   variable lengths differ (found for 'campus_id')
  </code></pre>
  
  <p>I looked at the NA fields and there is none </p>
  
  <pre><code>sum(is.na(stree))
  # [1] 0
  </code></pre>
  
  <p>and I also checked the lengths of the individual columns, they are all same. </p>
  
  <pre><code>length(stree[1,])
  # [1] 5
  length(stree[,1])
  # [1] 2412147
  length(stree[,2])
  # [1] 2412147
  length(stree[,3])
  # [1] 2412147
  length(stree[,4])
  # [1] 2412147
  length(stree[,5])
  # [1] 2412147
  </code></pre>
  
  <p>Can anyone tell me why am I getting this error?</p>