[问题类型]:
程式咨询(我想用R 做某件事情,但是我不知道要怎么用R 写出来)
[软件熟悉度]:
入门(写过其他程式,只是对语法不熟悉)
[问题叙述]:
我想要建构交叉表,
但目前只会用Filter后group_by配合summarise每一个,最后再cbind,
这样好像没有效率,请问有什么办法可以直接产生呢?
资料格式为
https://imgur.com/a/7M9oXYL
[程式范例]:
library(magrittr)
library(dplyr)
test1 <- Total_test1 %>%
filter(FW == 1) %>%
group_by(,Difficulty) %>%
summarise(NewFW = mean(E))
test2 <- Total_test1 %>%
filter(FW == 2) %>%
group_by(,Difficulty) %>%
summarise(OldFW = mean(E))
test3 <- Total_test1 %>%
group_by(,Difficulty) %>%
summarise(TotalE = mean(E))
cbind(test1,test2[,2],test3[,2])
目标是希望这样:
New Old Total
Low 0.23 0.1 0.13
Mid 0.3 0.13 0.22
High 0.1 0.32 0.31