![](/img/trans.png)
[英]Dplyr: How to Rearrange and Split a Dataframe by A Categorical Group Within a Pivot Table Showing Summary Statistics in R
[英]Drop a Categorical Level <- Dplyr <- Statistics With R
使用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)
任何幫助將不勝感激!
過濾掉不需要的類(並將其存儲到新變量中)之后,我可以運行以下代碼:
IRIS_TEST2$class <- factor(IRIS_TEST2$class)
這使我只有兩個級別,而且我能夠運行假設檢驗並找到置信區間
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.