Re: [R] R for simple stats

About this list Date view Thread view Subject view Author view Attachment view

From: Brett Magill (bmagill@earthlink.net)
Date: Sat 29 Jun 2002 - 04:21:32 EST


Message-id: <Springmail.0994.1025288492.0.55602600@webmail.pas.earthlink.net>

The code attached creates a function for descriptives statistics called
dstats. Enter the name of the column you want to summarize and dstats will
produce a nice summary. If you have a data frame of numeric variables and
want to summarize by column, you can use something like:

apply(data.frame.name,2,dstats)

wrap t( ) around the above to get the output in a format that I find more
useable.

Brett

dstats<-function(x,na.rm=T,digits=3) {

 dstats<-NULL

   dstats[1]<-mean(x,na.rm=na.rm)
   dstats[2]<-sd(x,na.rm=na.rm)
   dstats[3]<-var(x,na.rm=na.rm)
   dstats[4]<-min(x,na.rm=na.rm)
   dstats[5]<-max(x,na.rm=na.rm)
   dstats[6]<-length(unique(x))
   dstats[7]<-sum(!is.na(x))
   dstats[8]<-sum(is.na(x))
 
   dstats<-round(dstats,digits=digits)
   names(dstats)<-c("mean","sd","variance","min","max","unique","n","miss")

 return(dstats)
}
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Wed 16 Oct 2002 - 11:57:34 EST