[R] frequency

Brett Magill freud at starpower.net
Fri Mar 8 00:05:49 CET 2002


This function I wrote handles this, but without the cumulative percent, 
which is easy enough to see in any case.

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("To use this function across multiple columns use apply"))

}


gfaieta at katamail.com wrote:

>I'm quite new with R so sorry if I asked something very easy or complicated.
>I have a data frame with (for instance) 4 variables (4 columns) and 100 records. I would like to have a 'summary' table for each variable that shows me the following:
>
>variable 1      Freq.    %     % cumulative
>
>class 1           10        10%      10%
>class 2           20        20%      30%
>class 3           70        70%     100%
>
>Is there any kind of function in R that does somthing like this? Or is it necessary to create a customized function?
>Thank you in advanced.
>
>Giuseppe Faieta -statistician-
>Bologna (Italy)
>
>__________________________________________
>
>
>Fai i tuoi acquisti su www.kwshopping.it
>
>-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
>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
>_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>


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