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

From: Adrian Dusa <dusa.adrian_at_gmail.com>
Date: Sun 21 Jan 2007 - 14:38:41 GMT

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 combination of bases 3,3,2
> mat1 <- expand.grid(0:1, 0:2, 0:2)[,3:1]
> base <- c(3,3,2) # define the bases
> # now create the multiplier
> mbase <- c(rev(cumprod(rev(base))),1)[-1]
> # show the data
> mat1
> base
> mbase
> # combine with original
> cbind(mat1, conv=colSums(apply(mat1, 1, function(x) x*mbase)))

YES!
Thank you so much Jim, this made my day :)) Adrian

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
          +40 21 3120210 / int.101

______________________________________________
R-help@stat.math.ethz.ch 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.
Received on Mon Jan 22 01:44:09 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 21 Jan 2007 - 15:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.