我想为像这样的病人数据库建立一个应急表:
> data <- data.frame(Patient_nb = c("patient1", "patient1", "patient2", "patient3", "patient3"), Healthstate=c("Virus", "Alcool", "Alcool", "Virus", "Autoimmune"))
Patient_nb Healthstate
1 patient1 "Virus"
2 patient1 "Alcool"
3 patient2 "Alcool"
4 patient3 "Virus"
5 patient3 "Autoimmune"并创建一个表,以了解每个患者有多少健康状况,按患者分组;结果如下:
Alcool Virus Autoimmune
Alcool 2 1 0
Virus 1 2 1
Autoimmune 0 1 1可以说,第一排意味着有2名患者拥有"Alcool“健康状态,但只有1名患者同时拥有"Alcool”和"Virus“healthstate。
"table“函数给出了这个结果,所以它不是我要搜索的结果。
> table(data$Patient_nb, data$Healthstate)
Alcool Virus Autoimmune
patient1 1 1 0
patient2 1 0 0
patient3 0 1 1发布于 2017-05-29 10:12:30
我们需要一个crossprod
crossprod(table(data))https://stackoverflow.com/questions/44239875
复制相似问题