Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kruskal.test shows "All group levels must be finite" error. What is the problem?

Tags:

r

I have a data set having a value and a group, e.g.,

Val Grp
123 "A"
231 "A"
132 "A"
234 "A"
445 "B"
345 "B"
235 "B"
345 "B"

(The original dataset would be too large to show here.)

When I now do kruskal.test(data$Val, data$Grp), I get an error saying all group levels must be finite. When I check the data with is.finite(), I can see that all values are indeed finite.

The internet does not yield a lot of information on this error, so I have hope that someone could shed light on what this error means and what the problem could be.

like image 552
Eekhoorn Avatar asked Aug 08 '13 07:08

Eekhoorn


1 Answers

It should work if you run

data$Grp <- as.factor(data$Grp)

Then (as before):

kruskal.test(data$Val, data$Grp)

This is because Grp is a character not a factor and is.finite applied to an object of character class is always false (see ?is.finite).

like image 118
orizon Avatar answered Oct 23 '22 14:10

orizon