title: R: Kaggle Titanic Dataset Random Forest NAs introduced by coercion
body: <p>Im currently practicing R on the Kaggle using the titanic data set
  I am using the Random Forest Algorthim</p>
  
  <p>Below is the code</p>
  
  <pre><code>fit &lt;- randomForest(as.factor(Survived) ~ Pclass + Sex + Age_Bucket + Embarked
                  + Age_Bucket + Fare_Bucket + F_Name + Title + FamilySize + FamilyID, 
                  data=train, importance=TRUE, ntree=5000)
  </code></pre>
  
  <p>I am getting the following error</p>
  
  <pre><code>Error in randomForest.default(m, y, ...) : 
    NA/NaN/Inf in foreign function call (arg 1)
  In addition: Warning messages:
  1: In data.matrix(x) : NAs introduced by coercion
  2: In data.matrix(x) : NAs introduced by coercion
  3: In data.matrix(x) : NAs introduced by coercion
  4: In data.matrix(x) : NAs introduced by coercion
  </code></pre>
  
  <p>My data looks like below</p>
  
  <pre><code>$ Survived   : int  0 1 1 1 0 0 0 0 1 1 ...
  $ Pclass     : int  3 1 3 1 3 3 1 3 3 2 ...
  $ Sex        : Factor w/ 2 levels "female","male": 2 1 1 1 2 2 2 2 1 1...
  $ Age_Bucket : chr  "20-25" "30-40" "25-30" "30-40" ...
  $ Fare_Bucket: chr  "&lt;10" "30+" "&lt;10" "30+" ...
  $ Title      : Factor w/ 11 levels "Col","Dr","Lady",..: 7 8 5 8 7 7 7 4 8 8 ...
  $ F_Name     : chr  "Braund" "Cumings" "Heikkinen" "Futrelle" ...
  $ FamilySize : num  2 2 1 2 1 1 1 5 3 2 ...
  $ Embarked   : Factor w/ 3 levels "C","Q","S": 3 1 3 3 3 2 3 3 3 1 ...
  $ FamilyID   : chr  "Small" "Small" "Alone" "Small" ...
  </code></pre>
  
  <p>If i just type the below, I have no coercion issues which as far as i can see is the only place where coercion occurs to create NA values</p>
  
  <pre><code>as.factor(Survived)
  </code></pre>
  
  <p>Can anyone see the problem</p>
  
  <p>Thank you for your time</p>