In this recipe, we introduce Pearson's Chi-squared test, which is used to examine whether the distributions of categorical variables of two groups differ. We will discuss how to conduct Pearson's Chi-squared Test in R.
mtcars has already been loaded into a data frame within an R session. Since the
chisq.test function is originated from the
stats? package, make sure the library,
stats, is loaded.
Perform the following steps:
> ftable = table(mtcars$am, mtcars$gear) > ftable 3 4 5 0 15 4 0 1 0 8 5