[R] Most often pairs of chars across grouping variable

svga at arcor.de svga at arcor.de
Tue Jul 29 16:51:17 CEST 2008


Hi list,

is there a package or function to compute the frequencies of pairs of chars in a variable across a grouping variable? Eg:


d <- data.frame(ID=gl(2,3), F=c("A","B","C","A","C","D"))
> d
  ID F
1  1 A
2  1 B
3  1 C
4  2 A
5  2 C
6  2 D


Now I want to summarize the frequencies of all pairs A-B, A-C, A-D, B-C, B-D, C-D across ID:

   A B C D
A  - 1 2 1
B  - - 1 0
C  - - - 1


here, the combination A-C is most frequent. The real problem behind that is that 'F' codes diagnoses and I search for the most often pairs of diagnoses.

Thanks, Sven



More information about the R-help mailing list