我讀this SO question和that one,但仍然無法解決我的問題。我有以下data.table,其中只包括我的data.table的總列和行的幾個。R:wilcoxon測試錯誤:分組因子必須有2個水平
library(data.table)
structure(list(Patient = c("MB108", "MB108", "MB108", "MB108",
"MB108", "MB108", "MB108", "MB108", "MB108", "MB108"), Visit = c(1,
1, 1, 1, 9, 9, 9, 9, 12, 12), Stimulation = c("NC", "SEB", "PPD",
"E6C10", "NC", "SEB", "PPD", "E6C10", "NC", "SEB"), `CD38 ` = c(83.3,
63.4, 83.2, 91.5, 90.9, 70.9, 71, 88.4, 41.7, 47.9)), .Names = c("Patient",
"Visit", "Stimulation", "CD38 "), class = c("data.table", "data.frame"
), row.names = c(NA, -10L), .internal.selfref = <pointer: 0x102806578>)
我想這樣做在列4 t.test訪問時爲1,且當訪問是9. 我檢查對於NAS以及兩列的長度。
感謝您的幫助!
#na.omit(boolean_dt3)
#print(length(unlist(boolean_dt3[Visit== 1,4, with = FALSE])))
#print(length(unlist(boolean_dt3[Visit== 9,4, with = FALSE])))
wilcox.test(unlist(boolean_dt3[Visit== 1,4, with = FALSE])~ unlist(boolean_dt3[Visit== 9,4, with = FALSE]) , paired = T, correct=FALSE)
我不想使用的列名,因爲我通常不知道它。我也在運行多列測試,並將使用一個循環來運行所有測試。 – Rivka
聽起來像你會很難在所有列上自動運行它。每列只能有2個因子,每列不適合測試。 – CPak
爲什麼不呢?他們都是數字列。我想在訪問== 1並訪問== 9的人身上運行測試,並在我看到的2 – Rivka