我有這樣的數據集:如何格式化R中的describeBy表?
Defects.I Defects.D Treatment
1 2 A
1 3 B
和我想要做的檢測和隔離的缺陷,每處理一個分組的描述性統計。 搜索了一段時間後,我在名爲describeBy()的psych
庫上找到了一個很好的函數。 用下面的代碼:
describeBy(myData[1:2],myData$Treatment)
我得到這樣的輸出:
Treatment A
Mean. Median. Trimed.
Defects.I x x x
Defects.D x x x
Treatment B
Mean. Median. Trimed.
Defects.I x x x
Defects.D x x x
但在現實中我一直在尋找類似
Mean. Median. Trimed.
A B A B A B
Defects.I x x x x x x
Defects.D x x x x x x
數據
myData <- structure(list(Defects.I = c(1L, 1L), Defects.D = 2:3, Treatment = c("A",
"B")), .Names = c("Defects.I", "Defects.D", "Treatment"), class = "data.frame", row.names = c(NA,
-2L))
'l < - psych :: describeBy(myData [1:2],myData $ Treatment); do.call('cbind',l)[,order(sequence(lengths(l)))]' – rawr
@rawr這正是我期待的!你能把它作爲答案發布嗎?如果您提出1或2條評論,這將非常棒:) –