Re: [R] Non-conformable arrays

From: Gregory Ryslik <rsaber_at_comcast.net>
Date: Thu, 03 Mar 2011 00:06:57 -0500

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.



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. Received on Thu 03 Mar 2011 - 05:10:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 03 Mar 2011 - 06:40:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive