Let's say I have a dataframe
> col1<-c(1,5,2,6,8,1,3,8,9,1,8)
> col2<-c(1,2,1,1,2,2,1,2,2,1,1)
> df<-data.frame(col1,col2)
> df
col1 col2
1 1 1
2 5 2
3 2 1
4 6 1
5 8 2
6 1 2
7 3 1
8 8 2
9 9 2
10 1 1
11 8 1
I have ran the Kruskal-Wallis test with the data I have in df
> dfKW<-kruskal.test(col1~col2, data=df)
> dfKW
Kruskal-Wallis rank sum test
data: col1 by col2
Kruskal-Wallis chi-squared = 1.695, df = 1, p-value = 0.1929
What I wish to do is to extract the p-value into a vector (only the value without the label 'p-value'). I have tried this:
> dfKWx<-sapply(dfKW, '[', 'p.value')
> dfKWx
statistic.NA parameter.NA p.value method data.name
NA NA NA NA NA
With no luck, obviously.
The initial aid that I got from professor Google led me to the point I have described above.
All help is sincerely appreciated. Thank you!
PS. Please note that the data is only there to provide an example. I have not tested for the normal distribution nor do I wish to do so with these data. My original working data does not distribute normally, but I will not use it -or parts of it- as an example due to factors of confidentiality. The example data behaves similarly to my original working data.
This will give you the p value as a numeric
:
> dfKW$p.value
[1] 0.1929473
Look at the "Value" section in ?kruskal.test
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With