[R] problem about R

Jim Lemon jim at bitwrit.com.au
Tue Oct 2 11:51:34 CEST 2012


On 10/02/2012 02:50 PM, Leung Chen wrote:
> How to run pie chart for each categorical variable in a dataset?
>
Hi Leung,
I depends upon your definition of "categorical". If a character variable 
has 100 possible values, you won't get a very informative pie chart out 
of it. Therefore I suggest the following function as a start:

pie_shopping<-function(x,maxval=5) {
  xname<-deparse(substitute(x))
  for(var in 1:length(x)) {
   if(length(unique(x[,var])) <= maxval) {
    png(paste(xname,var,".png",sep=""))
     pie(table(x[,var]))
    dev.off()
   }
  }
}

Jim




More information about the R-help mailing list