I have a data set grouped by a factor (like e.g. cyl in the built in mtcars in R). I plotted the estimated density funtions (desityplot) for each factor using the lattice package, e.g.
library("lattice")
densityplot( ~mtcars$mpg[mtcars$cyl==4] )
densityplot( ~mtcars$mpg[mtcars$cyl==6] )
densityplot( ~mtcars$mpg[mtcars$cyl==8] )
Now I would like to create a densityplot() for the whole dataset but the estimation should disregard the different number of datapoints available for each factor, e.g.
densityplot( ~mtcars$mpg )
is not what I want, because there are more data points with cyl=8 than data points with cyl=6. Is it possible to estimate the density separately for each factor and than calculate some sort of "average" density? If not, what is the appropriate method for my purpose?