Getting mean and standard deviation from groups in a data.frame

后端 未结 2 1194
野的像风
野的像风 2021-01-17 01:07

I have heart rate data in the form of a list with the four categories 1AS, 1CS, 1AI, 1CI each of variable size. I would like to output mean and standard deviations for each

相关标签:
2条回答
  • 2021-01-17 01:10

    Another solution using ave:

    ave(DF$HR, DF$Group)
    

    gives the mean and

    ave(DF$HR, DF$Group, FUN=sd)
    

    with DF being your data frame.

    0 讨论(0)
  • 2021-01-17 01:12

    Assuming your data is in a data.frame called DF:

    by(DF$HR,DF$Group,mean)
    
    # DF$Group: 1AI
    # [1] 276
    # ------------------------------------------------------------------------------------------------------------------------------------------------------------- 
    # DF$Group: 1AS
    # [1] 246.7692
    # ------------------------------------------------------------------------------------------------------------------------------------------------------------- 
    # DF$Group: 1CI
    # [1] 217.625
    # ------------------------------------------------------------------------------------------------------------------------------------------------------------- 
    # DF$Group: 1CS
    # [1] 227.25
    
    by(DF$HR,DF$Group,sd)
    
    # DF$Group: 1AI
    # [1] 30.93946
    # ------------------------------------------------------------------------------------------------------------------------------------------------------------- 
    # DF$Group: 1AS
    # [1] 36.48551
    # ------------------------------------------------------------------------------------------------------------------------------------------------------------- 
    # DF$Group: 1CI
    # [1] 23.25595
    # ------------------------------------------------------------------------------------------------------------------------------------------------------------- 
    # DF$Group: 1CS
    # [1] 25.77236
    
    0 讨论(0)
提交回复
热议问题