Re: [R] could i change the ouput style on summary?

From: Jim Lemon <jim_at_bitwrit.com.au>
Date: Thu 06 Jul 2006 - 11:03:46 EST


Hi Zhi Jie,

I had a look at the summary function, and a minor extension seems to do what you want.

is.numeric.factor<-function(x) {

   if(is.factor(x)) {
    if(any(is.na(as.numeric(levels(x))))) return(FALSE)     return(TRUE)
   }
   return(FALSE)
}

summary.table<-function(x) {
  oldwarn<-options("warn")
  options(warn=-1)
  varnames<-names(x)
  num.index<-which(sapply(x,is.numeric))   fac.index<-which(sapply(x,is.numeric.factor))

  cat("Summary table for",deparse(substitute(x)),"\n")
  cat("             Min.  1st Qu.   Median     Mean  3rd Qu.
Max.\n")

  if(length(num.index)) {
   for(i in 1:length(num.index))

cat(formatC(c(varnames[num.index[i]],as.numeric(summary(x[[num.index[i]]]))),width=8),"\n")   }
  if(length(fac.index)) {
   for(i in 1:length(fac.index))

cat(formatC(c(varnames[fac.index[i]],as.numeric(summary(x[[fac.index[i]]]))),width=8),"\n")   }
  options(warn=oldwarn$warn)
}

However, I got interested in the problem in an unoccupied moment and wrote a set of functions named "describe" that may be an even more suitable solution to your problem. Let me know if you would like to try them.

Jim



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jul 05 21:12:26 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 05 Jul 2006 - 22:16:23 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.