[R] Non-conformable arrays

Gregory Ryslik rsaber at comcast.net
Thu Mar 3 06:06:57 CET 2011


Perfect! Thank you!
On Mar 2, 2011, at 10:55 PM, <Bill.Venables at csiro.au> <Bill.Venables at csiro.au> wrote:

> Here is one way.
> 
> 1. make sure y.test is a factor
> 
> 2. Use
> 
> table(y.test, 
>  factor(PredictedTestCurrent, levels = levels(y.test)) 
> 
> 3. If PredictedTestCurrent is already a factor with the wrong levels, turn it back into a character string vector first.
> 
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Gregory Ryslik
> Sent: Thursday, 3 March 2011 1:46 PM
> To: r-help Help
> Subject: [R] Non-conformable arrays
> 
> Hi Everyone,
> 
> I'm running some simulations where eventually I need to table the results. The problem is, that while most simulations I have at least one predicted outcome for each of the six possible categories, sometimes the algorithm assigns all the outcomes and one category is left out. Thus when I try to add the misclassification matrices I get an error. Is there a simple way I can make sure that all my tables have the same size (with a row or column of zeros) if appropriate without a messy "if" structure checking each condition?
> 
> To be more specific,
> 
> here's my line of code for the table command and the two matrices that I sometimes have. Notice that in the second matrix, the "fad" column is missing. Basically, I want all the columns and rows to be predetermined so that no columns/rows go missing. Thanks for your help!
> 
> Kind regards,
> Greg
> 
> table(y.test,PredictedTestCurrent):
> 
> 
>      PredictedTestCurrent
> y.test adi car con fad gla mas
>   adi   9   0   0   0   0   0
>   car   0   6   1   0   0   3
>   con   1   0   3   0   0   0
>   fad   0   0   0   2   5   4
>   gla   0   1   0   0   6   3
>   mas   0   0   0   1   4   4
> 
> 
>      PredictedTestCurrent
> y.test adi car con gla mas
>   adi   8   0   0   0   0
>   car   0   8   0   0   1
>   con   2   0   3   0   0
>   fad   0   1   0   4   7
>   gla   0   0   0   3   5
>   mas   0   2   0   6   3
> 
> 
> 
> 
> 	[[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.



More information about the R-help mailing list