【发布时间】:2018-01-06 09:18:41
【问题描述】:
使用 R 中的 dplyr 包,我正在尝试将分类变量从 3 级变为仅 2 级。我正在使用著名的 iris 数据集并尝试转换类变量(包含:“Iris-versicolor” , "Iris-setosa", & "Iris-virginica") 合二为一,只有两个层次(包含:"Iris-versicolor", "Iris-setosa")。所以,我想创建一个新的数据集,我想出了这个:
IRIS_TEST2 <- IRIS_TEST %>%
filter(class != "Iris-virginica")
所以,当我尝试对其进行假设检验时:
inference(y = sepal_length, x = class, data = IRIS_TEST2, statistic = "mean", type =
"ci", method = "theoretical", conf_level = .95)
我继续收到错误:
Error: Categorical variable has more than 2 levels, confidence interval is undefined,
use ANOVA to test for a difference between means
或者,我可以使用一种方法来附加“x =”以仅包含“Iris-versicolor”和“Iris-setosa”
inference(y = sepal_length, x = class, data = IRIS_TEST2, statistic = "mean", type =
"ci", method = "theoretical", conf_level = .95)
任何帮助将不胜感激!
【问题讨论】:
-
你考虑过使用
droplevels吗?以防万一,请参阅this question。 -
是的 - 你成功了,谢谢!
标签: r dplyr categorical-data