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 <shida...@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@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@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.