[R] count ties after rank?
David Winsemius
dwinsemius at comcast.net
Mon Nov 21 21:05:33 CET 2011
On Nov 21, 2011, at 2:50 PM, Peter Langfelder wrote:
> On Mon, Nov 21, 2011 at 11:36 AM, Hao, Zhaozhe <haozhaozhe at ou.edu>
> wrote:
>> Hello!
>>
>> I need to use Kruskal-Wallis test and post-hoc test (Dunn's
>> test) for my data. But when I searched around, I only found this
>> function: kruskal.test. But nothing for Dunn's test.
>>
>> So I started to write one myself. But I do not know how to
>> count ties in the data frame. I can use for loops but it seems long
>> and unnecessary since the rank function actually knows the ties. So
>> can anyone give me a hint on how I can "count" the number of ties?
>>
>
> If you just need the overall number of ties in a vector (say x), you
> can get it by
>
> nTies = length(x) - length(unique(x))
And if you wnat to know which ties are which you can do:
table(x)[table(x) > 1]
>
> This will not work if missing data are present, so you will have to
> remove those first.
>
table() would ignore missing data (assuming it were properly NA not-
valued).
> x <- sample(c(1:10,NA,NA), 20, replace=TRUE)
> table(x)[table(x) >1]
x
1 4 7 9 10
2 3 2 2 2
> x
[1] 7 10 3 9 NA NA 2 4 10 NA NA 4 5 9 6 4 1 1 7 8
--
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list