[R] Tabulating

Robin Hankin r.hankin at auckland.ac.nz
Sat Mar 1 01:58:03 CET 2003


Hi

I think Andy Liaw's suggestion can be modified to handle my
interpretation of Patrik's question; try:

R> data
 [1] 10 10 11 10 12 11 10 12 11 11 10 11
R> table(c(data,NA),c(NA,data))  -> x.tab
R> c(diag(x.tab), x.tab[upper.tri(x.tab)] + x.tab[lower.tri(x.tab)])
10 11 12 NA NA NA 
 1  1  0  5  2  2 
R> 

so the "5" means that there are five "10 11" or "11 10" pairs 


best


rksh



> 
> Hello,
> 
> I wonder if someone could send me suggestions on how to solve the following problem:
> 
> I have a vector of an arbitrary size (ex. data<-c(10,10,11,10,12,11,10,12,11,11,10,11)) and use the table function, which gives the following result
> 10  11  12
> 5    5     2
> 
> that's fine, but what I would like to do now is: 
> 
> construct new classes based on the number of classes from table, 10 10, 11 11, 12 12, 10 11, 10 12, 11 12. After that I would like to do tabulation on the pairs in data, and positions in pairs should be unimportant: 10 11 should be treated as the same class as 11 10.
> So the following result should be obtained:
> 10 10, 11 11, 12 12, 10 11, 10 12, 11 12
> 1 , 1 , 0 , 2 , 1 , 2
> 
> Remeber that it should be possible to do for an arbitrary number of classes.
> 
> Best regards,
> 
> Patrik.Waldmann at djingis.se


-- 

Robin Hankin, Lecturer,
School of Geography and Environmental Science
Tamaki Campus
Private Bag 92019 Auckland
New Zealand

r.hankin at auckland.ac.nz
tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042




More information about the R-help mailing list