R summarise by group sum giving NA

后端 未结 1 1118
慢半拍i
慢半拍i 2021-01-28 15:38

I have a data frame like this

Observations: 2,190,835
Variables: 13
$ patientid       4489, 4489, 4489, 4489, 4489, 4489, 4489, 4489, 4489, 4489, 4489         


        
相关标签:
1条回答
  • 2021-01-28 16:17

    By default, sum does not consider NA.

    Try this:

    nutrient_intake <- nutrient_data %>% 
      group_by(patientid, doseday, enteral) %>% 
      summarise(
        energy_kcal_kg_d=sum(energy_kcal_kg, na.rm=T),
        protein_g_kg_d=sum(prot_g_kg, na.rm=T),
        lipids_g_kg_d=sum(lipids_g_kg, na.rm=T),
        na_total_mmol_kg_d=sum(Na_mmol_kg, na.rm=T),
        K_total_mmol_kg_d=sum(K_mmol_kg, na.rm=T),
        Ca_mg_total_kg_d=sum(Ca_mg_kg, na.rm=T),
        P_mg_kg_d=sum(P_mg_kg, na.rm=T),
        Pi_mmol_kg_d=sum(Pi_mmol_kg, na.rm=T)
      )
    
    0 讨论(0)
提交回复
热议问题