Displaying multiple conditional distributions using lattice I have a data frame which contains several true/false columns, some numeric and a class (target) variable which has true/false values.
Now, how can I produce with R multiple barplots for all numerical and factor columns without having to specify each data frame's column name and imposing the class attribute's distribution per each feature of the data frame?  
Some example code : 
mydata<-data.frame(age=c(15,10,20),sugar=c("3","2","5"),spinach=c("true","true","false"),meat=c("false","false","true"),milk=c("false","true","false"),class=c("true","false","false"))


    age  sugar  spinach meat   milk   class
 1  15     3    true   false   false   true
 2  10     2    true   false   true   false
 3  20     5   false   true    false  false

So how can i see the distribution of the class attribute imposed on all other columns of the dataframe (numerical or factors) ?
Here is an example from WEKA: 

 A: Here is a (not so elegant) solution using lattice, where I consider quartiles in case the variables have numeric or integer values. Note that I assume that your classification factor is always in the latest position in your dataframe.
mydata <- data.frame(age=rnorm(100, 25, 4),
                     sugar=sample(0:10, 100, rep=T),
                     spinach=sample(c("true","false"), 100, rep=T),
                     meat=sample(c("true","false"), 100, rep=T),
                     milk=sample(c("true","false"), 100, rep=T),
                     class=sample(c("true","false"), 100, rep=T))

library(lattice)
library(gridExtra)
library(Hmisc)

plt <- list()
for (i in 1:(ncol(mydata)-1)) {
  if (is.numeric(mydata[,i])) vv <- cut2(mydata[,i], g=4)
  else vv <- mydata[,i]
  plt[[i]] <- barchart(xtabs(~ vv + mydata[,"class"]), horizontal=F, 
                       main=colnames(mydata)[i],
                       col=c("red","blue"), xlab="", ylab="", box.width=1, 
                       lattice.options=list(axis.padding=list(factor=0.5)),
                       scales=list(x=list(rot=ifelse(is.numeric(mydata[,i]),45,0))))
}
plt[[i+1]] <- barchart(xtabs(~ class, mydata), col=c("red","blue"), 
                       xlab="", ylab="", box.width=1,   
                       lattice.options=list(axis.padding=list(factor=0.5)),
                       horizontal=F, main="class")

do.call(grid.arrange, plt)



Using the same dataset with 10 more variables
mydata <- data.frame(age=rnorm(100, 25, 4),
                     sugar=sample(0:10, 100, rep=T),
                     spinach=sample(c("true","false"), 100, rep=T),
                     meat=sample(c("true","false"), 100, rep=T),
                     milk=sample(c("true","false"), 100, rep=T),
                     replicate(10, sample(c("true","false"), 100, rep=T)),
                     class=sample(c("true","false"), 100, rep=T))

this is the base version (you will still need the Hmisc library):
opar <- par(mfrow=c(4,4))
for (i in 1:15) {
  if (is.numeric(mydata[,i])) vv <- cut2(mydata[,i], g=4)
  else vv <- mydata[,i]  
  barplot(xtabs(~ mydata[,"class"] + vv), col=c("red","blue"),
          main=colnames(mydata)[i],
          las=ifelse(is.numeric(mydata[,i]), 2, 1))
}
barplot(xtabs(~ class, mydata), col=c("red","blue"), main="class",
        las=ifelse(is.numeric(mydata[,i]), 2, 1))
par(opar)

A: Give a bit more detail & someone may give you a sample script, but in principle, you can address each column within your dataframe as frame[n] rather than frame$column. Therefore, once you have a function which performs your design analysis, in this case a lattice, you can enclose it in a for loop and perform your analysis function with the current value of n.
