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
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.
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