[R] R for simple stats
Brett Magill
bmagill at earthlink.net
Fri Jun 28 20:21:32 CEST 2002
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 at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list