You should add a comment on why this works at all.  A cursory reading lead me to believe that you are getting your `i` and `index` mixed up.  It appears that the svm library is able to deal with features being in an arbitrary order.