[R] prevent surpressing zero frequencies

Christian Schulz c.schulz at metafacts.de
Fri May 10 15:00:11 CEST 2002


Hello,
i use the fct. to get the Freq result's, but it's too bad that
the codes which are not used are supressed instead of write a 0 for not 
used 
categories.
( in any way i must say R that codes i.e. from 1:10  are possible ???)

thanks & regards,christian


$Q82
      Count Prcnt
3         2    20
5         2    20
6         2    20
7         1    10
8         3    30
Total    10   100

$Q84
      Count Prcnt
5         1  16.7
6         1  16.7
7         2  33.3
8         2  33.3
Total     6 100.0


Freq <- function(x){
  xmat<-as.matrix(x)
  ifelse (ncol(xmat)==1,{
  Count<-table(x)
  Total<-sum(Count)
  Prcnt<-100*(Count/Total)
  x1<-cbind(Count,Prcnt)
  x2<-cbind(Total,sum(Prcnt))
  Frequency.Table<-as.data.frame(rbind(x1,x2))
  c<-nrow(Frequency.Table)
  rownames(Frequency.Table)[c]<-"Total"
  return(Frequency.Table)}
  ,
  return("Use  apply(data,2,Freq)"))
  }


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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