[R] Kruskal.test

Rui Barradas ruipbarradas at sapo.pt
Tue Jul 9 20:32:14 CEST 2013


Hello,

Another possibility is to use the formula interface.


x <- scan(what = "character", text = "
a   a   a   a    a    b   b    b    c    c   c    c")
y <- scan(text = "
2  4    5   2    7    2   2    6    3    7   9    3")

kruskal.test(y ~ factor(x))

dat <-
structure(list(x = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
3L, 3L, 3L, 3L), .Label = c("a", "b", "c"), class = "factor"),
     y = c(2, 4, 5, 2, 7, 2, 2, 6, 3, 7, 9, 3)), .Names = c("x",
"y"), row.names = c(NA, -12L), class = "data.frame")

kruskal.test(y ~ x, data = dat)


Hope this helps,

Rui Barradas

Em 09-07-2013 18:48, arun escreveu:
> Hi,
> ?kruskal.test()
>   a<- c(2,4,5,2,7)
>   b<- c(2,2,6)
>   c<- c(3,7,9,3)
>   kruskal.test(list(a,b,c))
> #
>   #  Kruskal-Wallis rank sum test
> #
> #data:  list(a, b, c)
> #Kruskal-Wallis chi-squared = 2.003, df = 2, p-value = 0.3673
> A.K.
>
>
> Hi
>
> I need an expression in R to apply a kruskal.test to this data (for example).
> a   a   a   a    a    b   b    b    c    c   c    c
> 2  4    5   2    7    2   2    6    3    7   9    3
> a, b and c could be consider different vectors. How can I apply this
>   test to this data? (probably the data isn't good to this test, but I
> onlu need the expression).
>
> Thank you very much
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list