如何在R中打印摘要数据?

时间:2017-02-10 09:02:07

标签: r

print(results)
       symptom1     disease
      Headache     Chicken pox
         Fever     Chicken pox
loss of appetite   Chicken pox
Red Color rashes   Chicken pox
         Scabs     Chicken pox
     Shivering     Malaria
         Fever     Malaria
    vomitings     Malaria
  muscle pain     Malaria
     sweating     Malaria
 table<-subset(results,symptom1=="Headache"|symptom1=="Fever"|symptom1=="Scrabs")
 > print(table)
 symptom1     disease
1 Headache Chicken pox
2    Fever Chicken pox
7    Fever     Malaria
> summary(table)
              symptom1        disease 
    Fever           :2   Chicken pox:2  
    Headache        :1   Malaria    :1  
    loss of appetite:0                  
    muscle pain     :0                  
    Red Color rashes:0                 
      Scabs           :0                  
      (Other)         :0  

我如何打印价值水痘。我想在摘要中打印具有更多价值的疾病(表) 在这种情况下水痘
我希望我的问题很明确。 谢谢你提前

1 个答案:

答案 0 :(得分:0)

我们可以使用dplyr

执行此操作
library(dplyr)
table %>% 
  group_by(disease) %>%
  mutate(n = n()) %>% 
  ungroup() %>%
  filter(n==max(n)) %>%
  select(-n)