search for: factorlevels

Displaying 2 results from an estimated 2 matches for "factorlevels".

Did you mean: factorlevel
2012 Mar 15
2
Ggplot barchart drops factor levels: how to show them with zero counts?
Hello, When plotting a barchart with ggplot it drops the levels of the factor for which no counts are available. For example: library(ggplot) mtcars$cyl<-factor(mtcars$cyl) ggplot(mtcars[!mtcars$cyl==4,], aes(cyl))+geom_bar() levels(mtcars[!mtcars$cyl==4,]) This shows my problem. Because no counts are available for factorlevel '4', the label 4 dissapears from the plot. However, I
2011 Mar 27
1
run function on subsets of matrix
...gh different 'factor' levels for (i in unique(fac)) print(apply(m[fac==i,],2,mean)) Now, the problem is that if a value in 'fac' only occurs once, the 'apply' function will complain. But I think, this can also be written more cleverly using some R style construct using factorlevels. Thanks