kruskal.test(y, groups)
The returned p.value should be interpreted carefully. It is only a large-sample approximation whose validity increases with the smallest of the group sizes.
Under the null hypothesis, the Kruskal-Wallis statistic has an asymptotic chi-square distribution with k - 1 degrees of freedom, where k is the number of groups.
Lehmann, E. L. (1975). Nonparametrics: Statistical Methods Based on Ranks. Oakland, Calif.: Holden-Day.
holl.y # data from Hollander and Wolfe (1973), p. 116 [1] 2.9 3.0 2.5 2.6 3.2 3.8 2.7 4.0 2.4 2.8 3.4 3.7 2.2 2.0 holl.grps # a category object [1] 1 1 1 1 1 2 2 2 2 3 3 3 3 3 attr(, "levels"): [1] "Normal Subjects" "Obstr. Airway Disease" "Asbestosis" kruskal.test(holl.y, holl.grps) # Now suppose the data is in the form of a table already, # with groups in columns; note this implies that group # sizes are the same. tab.data # fictional matrix of data Grp 1 Grp 2 Grp 3 Obs1 0.38 0.52 0.08 Obs2 0.58 0.02 0.97 Obs3 0.15 0.59 0.47 Obs4 0.72 0.94 0.92 Obs5 0.09 0.24 0.59 Obs6 0.66 0.94 0.77 # generate 'y' and 'groups': y2 <- as.vector(tab.data) gr <- factor(as.vector(col(tab.data))) # if groups are columns kruskal.test(y2, gr)