-1
A
回答
2
A table
本質上是一個matrix
,所以你可以使用它,就像你使用矩陣一樣。
當您在兩個項目上使用table
時,rownames
成爲第一項的唯一值,而colnames
成爲第二項的唯一值。
下面是一個例子:
out <- table(state.division, state.region)
out
# state.region
# state.division Northeast South North Central West
# New England 6 0 0 0
# Middle Atlantic 3 0 0 0
# South Atlantic 0 8 0 0
# East South Central 0 4 0 0
# West South Central 0 4 0 0
# East North Central 0 0 5 0
# West North Central 0 0 7 0
# Mountain 0 0 0 8
# Pacific 0 0 0 5
unique(state.division)
# [1] East South Central Pacific Mountain West South Central
# [5] New England South Atlantic East North Central West North Central
# [9] Middle Atlantic
# 9 Levels: New England Middle Atlantic South Atlantic ... Pacific
unique(state.region)
# [1] South West Northeast North Central
# Levels: Northeast South North Central West
因此,如果我們想在第一個值訂購,我們需要你的表的rownames
訂購:
out[order(rownames(out)), ]
# state.region
# state.division Northeast South North Central West
# East North Central 0 0 5 0
# East South Central 0 4 0 0
# Middle Atlantic 3 0 0 0
# Mountain 0 0 0 8
# New England 6 0 0 0
# Pacific 0 0 0 5
# South Atlantic 0 8 0 0
# West North Central 0 0 7 0
# West South Central 0 4 0 0
相關問題
- 1. 訂購雙向表從大到小
- 2. 如何訂購數據中的R
- 3. Java訂購的雙向鏈表列表程序
- 4. 如何訂購預購表
- 5. R中的具體訂購
- 6. R - ggvis - 訂購軸
- 7. 訂購,使用R
- 8. 如何訂購列表中的元素
- 9. 查看R中的雙向表格
- 10. 雙向數據表中的R
- 11. R中的雙向列聯表
- 12. 如何訂購表格?
- 13. 在R中訂購一個向量的矩陣interms
- 14. 如何訂購
- 15. 在R中訂購較低的矩陣
- 16. R/VennDiagram中集合的手動訂購
- 17. Grafana - 如何在表格中訂購欄
- 18. 如何在Python中訂購此列表?
- 19. Ember雙向裝訂
- 20. 隨機化R訂購
- 21. R ggplot羣內訂購吧
- 22. 如何在一個boxplot圖表上訂購盒子? (r)
- 23. 訂購C#中的列表
- 24. 如何訂購R中第二列的數據框?
- 25. 如何以相同的方式訂購列表QuerySets在Django中訂購?
- 26. 如何在AngularJS中訂購
- 27. 如何在XSLT中訂購?
- 28. 如何在SQL中訂購
- 29. 如何訂購我的表(SQL和JS)
- 30. 如何訂購表格的行?
給我們一些數據工作等等,例子,以及迄今爲止所做的。 – Ananta
歡迎來到SO。請爲我們提供一個[可重現的示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。 – sgibb
或許'ExamSex [order(rownames(ExamSex)),]'?默認情況下,我希望「考試」的值最終成爲你的「rownames」,但正如其他人所建議的那樣,顯示一些示例數據,你期望的輸出和你嘗試過的。 – A5C1D2H2I1M1N2O1R2T1