Chris
Chris

Reputation: 820

Why does CrossTable fail with "'x' must have at least 2 elements" on a vector with a single value?

library(gmodels)    
a <- c(4,4,4,4,4)
CrossTable(a, chisq=FALSE, prop.chisq=FALSE)

produces: Error in chisq.test(t, correct = FALSE) : 'x' must at least have 2 elements

a <- c(4,5,6,7,8)
CrossTable(a, chisq=FALSE, prop.chisq=FALSE)

produces the frequency table you'd expect.

Upvotes: 0

Views: 2577

Answers (1)

atiretoo
atiretoo

Reputation: 1902

The result is a single cell: a count of 5 of the value 4. CrossTable() wants at least 2 cells in the table.

Upvotes: 1

Related Questions