[R] multiple bases to decimal (was: comparing two matrices)

2007-01-21 Thread Adrian Dusa
Hi again, I was contemplating the solution using base 3: set.seed(3) mat2 <- matrix(sample(0:2, 15, replace=T), 5, 3) Extracting the line numbers is simple: bases <- c(3, 3, 3)^(2:0) # or just 3^(2:0) colSums(apply(mat2, 1, function(x) x*bases)) + 1 [1] 7 23 25 8 1 The problem is somet

Re: [R] multiple bases to decimal (was: comparing two matrices)

2007-01-21 Thread jim holtman
I think you are computing your bases in the wrong way. If the data represents 3 columns with base 3,3,2, then the multiplier has to be c(6,2,1) not c(9,3,1). I think this should compute it correctly: # create a matrix of all combination of bases 3,3,2 mat1 <- expand.grid(0:1, 0:2, 0:2)[,3:1] bas

Re: [R] multiple bases to decimal (was: comparing two matrices)

2007-01-21 Thread Adrian Dusa
On Sunday 21 January 2007 16:30, jim holtman wrote: > I think you are computing your bases in the wrong way. If the data > represents 3 columns with base 3,3,2, then the multiplier has to be > c(6,2,1) not c(9,3,1). I think this should compute it correctly: > > # create a matrix of all combinatio