title: predict.svm function R text mining?
body: <p>I have a training set that contains sentences and labels(1 et -1 ).
  After creating an svm model. I want to predict the label and the score of my new data.
  This is my code :</p>
  
  <pre><code>library(tm);
  require(RcmdrPlugin.temis);
  library(RTextTools);
  require(e1071)
  news=read.csv("C:..polarity.csv",header=F,sep=';') # the training data
  traindata &lt;- as.data.frame(news[1:196,]);
  trainvector &lt;- as.vector(traindata[,1]); # Choose the sentences without the labels
  trainsource &lt;- VectorSource(trainvector);
  traincorpus &lt;- Corpus(trainsource) # Create a training corpus
  #Cleaning the training corpus
  traincorpus &lt;- tm_map(traincorpus,stripWhitespace)
  traincorpus &lt;- tm_map(traincorpus,tolower)
  traincorpus &lt;- tm_map(traincorpus, removeWords,stopwords("french"))
  traincorpus &lt;- tm_map(traincorpus,removeNumbers)
  traincorpus &lt;- tm_map(traincorpus, function(x)
  gsub("(['’\n??]|[[:punct:]]|[[:space:]]|[[:cntrl:]])+", " ", x))
  corpus1 &lt;- Corpus(DirSource("C.../file", encoding="UTF-8"),
  readerControl=list(language="fr"))  # Import the corpus of test
  testcorpus=corpus1 # create a copy and cleaning it
  testcorpus &lt;- tm_map(testcorpus,stripWhitespace)
  testcorpus &lt;- tm_map(testcorpus,tolower)
  testcorpus &lt;- tm_map(testcorpus, removeWords,stopwords("french"))
  testcorpus &lt;- tm_map(testcorpus,removeNumbers)
  testcorpus &lt;- tm_map(testcorpus, function(x)
  gsub("(['’\n??]|[[:punct:]]|[[:space:]]|[[:cntrl:]])+", " ", x))
  #Creating the dtm of test and train corpus with words stemming 
  tr_matrix &lt;- create_matrix(traincorpus, language="french", stemWords=TRUE,
  removeStopwords=TRUE,weighting=weightTf)
  tr=as.matrix(tr_matrix)
  ts_matrix &lt;- create_matrix(testcorpus, language="french", stemWords=TRUE,
  removeStopwords=TRUE,weighting=weightTf)
  ts = as.matrix(ts_matrix)
  y=traindata[,2]
  model&lt;-svm(y~tr)
  pred=fitted(model)
  pred &lt;- predict(model, ts, decision.values = TRUE, probability = TRUE,na.action=TRUE)
  </code></pre>
  
  <p>I have this error : 
  Erreur dans matrix(ret$dec, nrow = nrow(newdata), byrow = TRUE, dimnames = list(rowns,  : 
  la longueur de 'dimnames' [1] n'est pas égale à l'étendue du tableau
  I guess it is because of the structure differnce between the training data and the new data.
  Can someone help me please?
  Thanks</p>