> On 24 Aug 2017, at 11:58 , peter dalgaard <pda...@gmail.com> wrote: > > M <- as.matrix(do.call(expand.grid, rep(list(0:1),5))) > M > # This is just 0:31 encoded as (little-endian) binary > apply(M, 1, function(i) sum((2^(0:4))[i])) > > # now, use rows of M for logical indexing into "A"-"E" > mode(M) <- "logical"
Whoops. That apply() line should either come _after_ conversion to logical, or read apply(M, 1, function(i) sum(2^(0:4) * i)) As in: > M <- as.matrix(do.call(expand.grid, rep(list(0:1),5))) > apply(M, 1, function(i) sum(2^(0:4) * i)) [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 [26] 25 26 27 28 29 30 31 -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd....@cbs.dk Priv: pda...@gmail.com ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.