[R] Contingency table and zeros
David Duffy
David.Duffy at qimr.edu.au
Tue Mar 7 01:46:04 CET 2006
> Let's assume I have a vector of integers :
> > myvector <- c(1, 2, 3, 2, 1, 3, 5)
> For this, I create a table with ;
> > mytable <- table(myvector)
> 1 2 3 5
> 2 2 2 1
> However, table() returns an array of integers, mytable[4] returns the
> occurence number of the "5" item, which makes this table hard to index.
> I would prefer to have a data structure where mytable[4] could return 0,
> as there is no "4" in my vector.
>
?tabulate
so cumsum(tabulate(myvector))
More information about the R-help
mailing list