Contingency table and zeros

Nicolas Perot np at
Mon Mar 6 10:56:56 CET 2006


Let's assume I have a vector of integers :
 > myvector <-  c(1, 2, 3, 2, 1, 3, 5)

My purpose is to obtain the cumulative distribution of these numerical 
data, i.e. something like :

value	nb_occur.
<=1    2
<=2    4
<=3    6
<=4    6
<=5    7

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.

table() may not be the proper way to do it.

For the moment, I use a loop which scans the vector from its lowest 
value to its highest, and counts the number of times each value appears.

Is there a built-in function, or a table() option to do such a task ?



Dear all 
I was trying to load a bluefuse file into R , by the read.maimages function but I am recieving the error message 
"Error in readBlueFuseHeader(fullname) : Second line not blank"
Could you please help me how to solve this 

VU medisch centrum. Kennis maakt ons beter.
Lustrum 20056 

More information about the R-help mailing list