title: setting bagging in R adabag
body: <p>I cannot seem to get <code>adabag</code>'s <code>bagging</code> and <code>predict.bagging</code> to work.</p>
  
  <p>In <code>predict.bagging</code> manual page, there is the following:</p>
  
  <pre><code> library(adabag)
   library(rpart)
   data(iris)
   names(iris)&lt;-c("LS","AS","LP","AP","Especies")
   sub &lt;- c(sample(1:50, 25), sample(51:100, 25), sample(101:150, 25))
   iris.bagging &lt;- bagging(Especies ~ ., data=iris[sub,], mfinal=10)
   iris.predbagging&lt;- predict.bagging(iris.bagging, newdata=iris[-sub,])
   iris.predbagging
  </code></pre>
  
  <p>That is nice and working. However, when I change the <code>newdata</code> in <code>predict.bagging</code> a bit, it stops working.</p>
  
  <p>Mainly, I cannot really delete or change the <code>Especies</code> column, which is weird, since that one is the one I am supposed to be predicting! An example.</p>
  
  <pre><code>testdata &lt;- iris[-sub, ]
  result &lt;- predict.bagging(iris.bagging, newdata=testdata)
  </code></pre>
  
  <p>....this works fine and is almost carbon copy of the example. However, this produces an error</p>
  
  <pre><code>testdata &lt;- iris[-sub, -5] #this deletes the Especies column!
  result &lt;- predict.bagging(iris.bagging, newdata=testdata)
  </code></pre>
  
  <p>but also this</p>
  
  <pre><code>testdata &lt;- iris[-sub, ] 
  testdata$Especies &lt;- c("virginica") #sets up everything as virginica
  result &lt;- predict.bagging(iris.bagging, newdata=testdata)
  </code></pre>
  
  <p>produces an error! </p>
  
  <p>What is going on? I want to make a classifier using <code>bagging</code>, but I can't know the results in advance, that defeats the point.</p>
  
  <p>edit: Allright, it gets even weirded.</p>
  
  <pre><code>&gt; testdata &lt;- iris[150,]
  &gt; predict.bagging(iris.bagging, newdata=testdata) #all working
  &gt; testdata
       LS AS  LP  AP  Especies
  150 5.9  3 5.1 1.8 virginica
  &gt; is(testdata)
  [1] "data.frame" "list"       "oldClass"   "vector"    
  &gt; testdata$Especies = "virginica"
  &gt; testdata
       LS AS  LP  AP  Especies
  150 5.9  3 5.1 1.8 virginica    #!!!the same thing!!!
  &gt; is(testdata)
  [1] "data.frame" "list"       "oldClass"   "vector"    #the same object type!!!
  &gt; 
  &gt; predict.bagging(iris.bagging, newdata = testdata)
  Error in matrix(unlist(value, recursive = FALSE, use.names = FALSE), nrow = nr,  : 
    length of 'dimnames' [2] not equal to array extent
  In addition: Warning messages:
  1: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'
  2: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'
  3: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'
  4: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'
  5: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'
  6: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'
  7: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'
  8: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'
  9: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'
  10: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'
  &gt; 
  </code></pre>