Descriptive Statistics for Continuous Variables
Summary of a Continuous Variable
summary(varname)
Provides minimum, 1st quartile (25%tile), median, mean, 3rd quartile (75%tile) and maximum values of varname.
summary(age)
**Min. 1st Qu. Median *Mean 3rd Qu. *Max.
61.00 **63.00 *66.00 *66.94 **70.00 75.00
Mean
mean(varname)
mean(age)
[1] 66.94286
Standard Deviation
sd(varname)
sd(age)
[1] 4.458586
Median
median(varname)
median(age)
[1] 66
Descriptive Statistics by Subsets
To compute descriptive statistics for continuous variables by group, use the tapply() function
tapply(varname, groupname, statistic)
Provides statistics for varname by groupname. Statistics can be summary, mean, sd and others.
tapply(bmi,anyS,mean)
This gives the mean of bmi separately for those with variable anyS=0 and anyS=1.
***0 1
23.4358 23.6796
Similarly, we can compute the standard deviation for bmi in each of these two groups.
tapply(bmi,anyS,sd)
**0 1
4.971052 4.665697