Oriol Prat Oriol Prat - 1 year ago 85
R Question

rare error when running my function in R

I have two function. One to train a classifier and one to predict test data. If I run the predict function step by step it works fine, however If I call the predict function I get an error. I can't know what is happening due to the code of the function has no errors compiled manually. I've upload the two functions and the data on Github.you can access here

modelFit=mdp(Class = dades[,1],data=dades[,-1],lambda = 1,info.pred = T)
predict.mdp(modelFit, dades[1:5,-1])
Error in D[row, i] : subscript out of bounds

Thank you for anything you can do to help

Answer Source

The reason I could see was that in D[row, i] , variable row was overshooting the number of rows in D. row itself is derived from vec.new : for(row in vec.new)

This piece is the culprit :


vec.new starts from nrow(D)+1 , so even the first element is actually just beyond the size of D .

You can insert cat(row) in code and see.

I guess you will have to think about what start should be.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download