[R] Error in object$tables[[v]] : subscript out of bounds

Uwe Ligges ligges at statistik.tu-dortmund.de
Sun Mar 14 19:50:27 CET 2010



On 14.03.2010 19:12, Amy Hessen wrote:
>
>
>
>
> Hi Uwe,
> Thanks for your reply.
>
> I did not understand what you mean and I still receive the error message.

OK, so which version of R and which version of e1071 is this?
Do you have any objects in your workspace?

I do not get an error message, just a nonsense result as requested.



 > Do you mean that something is wrong in computing FORMULA?
>
> I want to use formula in Naïve instead of using the class label, could you please tell me where is the wrong?


As I said, the left hand side must label the classes, you chose the 
first variable in iris which is NOT a factor.

You need:

mymodel <- naiveBayes(Species ~ ., data = iris, cross = 3)

or if you want to compute ion the data before:

class_label<- names(iris)[5] # !!!


Best,
Uwe



> Cheers,
> Amy
>
>> Date: Sun, 14 Mar 2010 15:30:36 +0100
>> From: ligges at statistik.tu-dortmund.de
>> To: amy_4_5_84 at hotmail.com
>> CC: r-help at r-project.org
>> Subject: Re: [R] Error in object$tables[[v]] : subscript out of bounds
>>
>>
>>
>> On 14.03.2010 11:55, Amy Hessen wrote:
>>>
>>>
>>>
>>> Hi,
>>> Could you please tell me how I correct the following error message?
>>> “Error in object$tables[[v]] : subscript out of bounds”
>>>
>>> This is the code:
>>>
>>> library(e1071)
>>> data(iris)
>>> attach(iris)
>>> class_label<- names(iris)[1]
>>
>> This is not the name for the class variable of the wiris data from R.
>>
>>
>>> myformula<- formula(paste(class_label,"~ ."))
>>
>> Why do you construct this in a so complicated manner rather than typing
>> the formula directly?
>>
>>
>>> mymodel<-naiveBayes(myformula, iris,cross=3)
>>
>> naiveBayes sort of fails (well, it runs smoothly but the result won't
>> make sense) here since it expects a class variable.
>>
>>
>>> predict(mymodel,iris) ##Error in object$tables[[v]] : subscript out of bounds
>>
>>
>> Works for me.
>>
>>
>> Please upgrade R, e1071 and run in a clean session to see that the code
>> above does not fail. Although it makes absolutely no sense.
>>
>> Uwe Ligges
>>
>>
>>
>>> Cheers,
>>> Amy
>>> _________________________________________________________________
>>> Link all your email accounts and social updates with Hotmail. Find out now.
>>>
>>> [[alternative HTML version deleted]]
>>>
>>>
>>>
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>   		 	   		
> _________________________________________________________________
> Looking for a new home? With all the latest places, searching has never been easier.
> http://clk.atdmt.com/NMN/go/157631292/direct/01/



More information about the R-help mailing list