Bug 16719 - kruskal.test documentation for formula
Summary: kruskal.test documentation for formula
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Documentation (show other bugs)
Version: R 3.2.3
Hardware: Other Other
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2016-02-18 22:50 UTC by k_bugzilla
Modified: 2018-07-01 07:44 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description k_bugzilla 2016-02-18 22:50:29 UTC
R version 3.2.3

from ?kruskal.test:
"formula
a formula of the form response ~ group where response gives the data values and group a vector or factor of the corresponding groups."

data(mtcars)
mtcars$type <- rep(letters[1:2], c(16, 16))
is.vector(mtcars$type) ## TRUE

kruskal.test(mpg ~ type, mtcars)
## Error in kruskal.test.default(c(21, 21, 22.8, 21.4, 18.7, 18.1, 14.3,  : 
##   all group levels must be finite

mtcars$type <- rep(1:2, c(16, 16))
kruskal.test(mpg ~ type, mtcars) # works

mtcars$type <- factor(mtcars$type)
kruskal.test(mpg ~ type, mtcars) # works

Maybe instead of 'vector' it should read 'numeric'? Or should kruskal.test also work with 'character' for grouping?
Comment 1 Kurt Hornik 2018-07-01 07:44:48 UTC
Fixed now in the trunk with c74945.

I simply removed

-        if (!all(is.finite(g)))
-            stop("all group levels must be finite")

from the kruskal.test() and fligner.test() default methods.

My code from about 20 years ago, and I no longer recall why I thought the is.finite() tests would be necessary ...