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
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html