[R] Tabulating
Liaw, Andy
andy_liaw at merck.com
Fri Feb 28 15:20:15 CET 2003
If I understand you correctly, here's a quick and dirty way:
## Simulate some data:
x1 <- sample(3, 20, replace=TRUE)
x2 <- sample(3, 20, replace=TRUE)
x.tab <- table(x1, x2)
x.count <- c(diag(x.tab), x.tab[upper.tri(x.tab)] + x.tab[lower.tri(x.tab)])
The first 3 elements of x.count will be (1,1), (2,2) and (3,3), followed by
(1,2)/(2,1), (1,3)/(3,1) and (2,3)/(3,2).
HTH,
Andy
> -----Original Message-----
> From: Patrik Waldmann [mailto:Patrik.Waldmann at djingis.se]
> Sent: Friday, February 28, 2003 6:10 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Tabulating
>
>
> 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
> [[alternate HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
------------------------------------------------------------------------------
More information about the R-help
mailing list