Skip to content
Prev 166659 / 398502 Next

summary with variance / sd

On Jan 11, 2009, at 4:38 PM, J?rg Gro? wrote:

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