Re: [R] confusion matrix

From: Richard M. Heiberger <rmh_at_temple.edu>
Date: Tue, 08 Mar 2011 15:28:05 -0500

You need to make your variables into factors and specify the levels.

> x <- c(1,3,4,5)
> table(x)


x
1 3 4 5
1 1 1 1
> factor(x)

[1] 1 3 4 5
Levels: 1 3 4 5
> table(factor(x))

1 3 4 5
1 1 1 1
> table(factor(x, levels=1:5))

1 2 3 4 5
1 0 1 1 1
>

Rich
On Tue, Mar 8, 2011 at 3:22 PM, Shi, Tao <shidaxia_at_yahoo.com> wrote:

> Hi list,
>
> Is there already a function somewhere to output the confusion matrix from
> two
> input vectors? "table" always automatically delete rows or columns with
> all
> 0's. For example, I would like the columns for "10" and "30" added back.
>
> Thanks!
>
> ...Tao
>
>
>
> 20 40 50 60 70 80 90 100
> 10 0 0 1 0 0 0 1 0
> 20 1 2 0 4 0 0 0 1
> 30 0 0 0 0 0 0 1 1
> 40 0 0 1 1 2 0 0 0
> 50 0 1 0 0 0 1 0 0
> 60 0 0 0 0 0 0 1 1
> 70 0 0 1 1 1 1 1 1
> 80 0 1 0 0 0 0 0 1
> 90 0 0 0 0 0 0 0 3
> 100 0 0 0 0 1 0 0 3
>
> ______________________________________________
> 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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

        [[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. Received on Tue 08 Mar 2011 - 20:30:52 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 Tue 08 Mar 2011 - 20:40:20 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