多個級別3路表我想打開以下,手動輸入的表,輸入作爲在R A data.frame,代碼here以下:車削一個data.frame與R中
tab <- data.frame(expand.grid(
Hair = c("Black", "Brown", "Red", "Blond"),
Eye = c("Brown", "Blue", "Hazel", "Green"),
Sex = c("Male", "Female")),
count = c(32,53,10,3,11,50,10,30,10,25,7,5,3,15,7,8,
36,66,16,4,9,34,7,64,5,29,7,5,2,14,7,8))
tab
Hair Eye Sex count
1 Black Brown Male 32
2 Brown Brown Male 53
3 Red Brown Male 10
4 Blond Brown Male 3
...
到一個表作爲原始HairEyeColor {datasets}
三維陣列中:
HairEyeColor
, , Sex = Male
Eye
Hair Brown Blue Hazel Green
Black 32 11 10 3
Brown 53 50 25 15
Red 10 10 7 7
Blond 3 30 5 8
, , Sex = Female
Eye
Hair Brown Blue Hazel Green
Black 36 9 5 2
Brown 66 34 29 14
Red 16 7 7 7
Blond 4 64 5 8
我試圖xtabs
ftable
和沒有成功。
'XTABS(計數〜,數據=標籤)'是不是? – thelatemail
@thelatemail相當簡潔,但有效。發佈它作爲答案的一些觀點... – Toni