Re: [R] Expand DF with all levels of a variable

2011-06-14 Thread Dimitris Rizopoulos
here is a solution with expand.grid(), a <- c(2,2,3,4,5,6,7,8,9) a.cut <- cut(a, breaks=c(0,2,6,9,12,13,15,16), right=FALSE ) x <- data.frame(a, a.cut) out <- expand.grid(a = 0, a.cut = setdiff(levels(a.cut), unique(a.cut))) rbind(out, x) I hope it helps. Best, Dimitris On 6/14/2011 1:32 P

[R] Expand DF with all levels of a variable

2011-06-14 Thread Patrick Hausmann
Dear list, I would like to expand a DF with all the missing levels of a variable. a <- c(2,2,3,4,5,6,7,8,9) a.cut <- cut(a, breaks=c(0,2,6,9,12), right=FALSE ) (x <- data.frame(a, a.cut)) # In 'x' the level "[0,2)" is "missing". AddMissingLevel <- function(xdf) { xfac <- factor( c("[0,2)