summary with variance / sd
On Jan 11, 2009, at 4:38 PM, J?rg Gro? wrote:
Hi, I have a data frame and would like to have summary statistics for grouped data. With summary() I get the central tendencies for the overall data. How can I get descriptive statistics with variances and standard deviations?
In the future, you really should do your own searching before posting
this sort of basic question.
help.search("standard deviation") produced reference to a function
with the obvious name "sd"
Using the same strategy for variance produces a longer list but "var"
is among them.
for example my data.frame: group x y exp 2 4 exp 3 5 exp 2 4 control 1 2 control 2 3 control 1 2
#Create dataframe ( and please note that you are asked to offer
examples in a form that does not require responders to create the
objects for you):
df1 <- read.table(stdin(), header=TRUE)
#Paste in the data:
0: group x y
1: exp 2 4
2: exp 3 5
3: exp 2 4
4: control 1 2
5: control 2 3
6: control 1 2
# empty line stops input.
by(data=df1, df1$group, summary)
by(data=df1, df1$group, sd)
by(data=df1, df1$group, var)
Or.... use negative indexing to exclude the first column, and add
some annotation to do it in one step
by(data=df1[-1], df1$group, function(x){ list(summary(x), "Group S.D.s
are ...", sd(x), "Group Variances are ...", var(x) )} )
You could also look at how the pro's do constructed summary() by
reviewing the code of:
base:::summary.default
base:::summary.data.frame
David Winsemius > > > > now I want tables with summary statistics (variances included) for > each group. > > Is there an easy way to get this? > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.