是否有一个函数可能是 table 或 xtabs 以下列方式计算数据 Titanic:
我不需要像“类”那样分离
df<-data.frame(Titanic)
tapply(df$Freq,list(df$Sex,df$Age,df$Survived),sum)
但输出应如下所示:“new_output”=
1 board_Crew board_Crew_Male 862
2 board_Crew board_Crew_Female 23
3 board_Crew_Male board_Crew_Male_Child 0
4 board_Crew_Female board_Crew_Female_Child 0
5 board_Crew_Male board_Crew_Male_Adult 862
6 board_Crew_Female board_Crew_Female_Adult 23
7 board_Crew_Male_Child board_Crew_Male_Child_No 0
8 board_Crew_Female_Child board_Crew_Female_Child_No 0
9 board_Crew_Male_Adult board_Crew_Male_Adult_No 670
10 board_Crew_Female_Adult board_Crew_Female_Adult_No 3
11 board_Crew_Male_Child board_Crew_Male_Child_Yes 0
12 board_Crew_Female_Child board_Crew_Female_Child_Yes 0
13 board_Crew_Male_Adult board_Crew_Male_Adult_Yes 192
14 board_Crew_Female_Adult board_Crew_Female_Adult_Yes 20
因为在这最后的数据上我可以建立一个图表
g <- graph.data.frame(new_output, directed=TRUE)
plot(g,layout=layout.reingold.tilford(g,root=1),edge.arrow.size=0.5)