[R] the format of the result

From: ronggui <0034058_at_fudan.edu.cn>
Date: Fri 01 Jul 2005 - 21:40:44 EST


I write a function to get the frequency and prop of a variable.

freq<-function(x,digits=3)
{naa<-is.na(x)
nas<-sum(naa)
if (any(naa))
x<-x[!naa]
n<-length(x)
ta<-table(x)
prop<-prop.table(ta)*100
res<-rbind(ta,prop)
rownames(res)<-c("Freq","Prop")

cat("Missing value(s) are",nas,".\n")
cat("Valid case(s) are",n,".\n")
cat("Total case(s) are",(n+nas),".\n\n")
print(res,digits=(digits+2))
cat("\n")
}

> freq(sample(letters[1:3],48,T),2)
Missing value(s) are 0 .
Valid case(s) are 48 .
Total case(s) are 48 .

         a b c
Freq 11.00 20.00 17.00
Prop 22.92 41.67 35.42

and i want the result to be like

         a b c
Freq 11.00 20.00 17.00
Prop 22.92% 41.67% 35.42%

how should i change my function to get what i want?

-- 
Department of Sociology
Fudan University,Shanghai
Blog:http://sociology.yculblog.com

______________________________________________
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 Fri Jul 01 21:46:34 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:08 EST