On Thu, Sep 26, 2013 at 2:02 PM, Sebastian Kruk <residuo.so...@gmail.com> wrote: > I have a list that gives me the number of occurrences of numbers 1, 2, 3 and > 4. > > > Sometimes a single in a casa just appears 0 and 1, in others only 2, and every > combination you can think of. > > > Eg > > >> Caso [1:2] > $ `9` > > > 0 1 > 2 10 > > > $ `13` > > > 0 2 > 2 4 > > > Can I turn it into a matrix consisting of 4 columns in which I put the > number of occurrences of the previous numbers, and for cases where it does > not appear any of those values put 0?
When creating Caso make the components factors with levels 0:4. dat <- list("9" = c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), "13" = c(0, 0, 4, 4, 4, 4)) Caso <- lapply(dat, factor, levels = 0:4) do.call(rbind, lapply(Caso, table)) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.