Re: [R] convert to binary to decimal

2007-02-17 Thread Henrik Bengtsson
On 2/16/07, Jim Regetz [EMAIL PROTECTED] wrote: Roland Rau wrote: On 2/16/07, Petr Pikal [EMAIL PROTECTED] wrote: Hi slight modification of your function can be probably even quicker: fff-function(x) sum(2^(which(rev(x))-1)) :-) Petr Yes, your function is slightly but

Re: [R] convert to binary to decimal

2007-02-16 Thread Roland Rau
On 2/16/07, Petr Pikal [EMAIL PROTECTED] wrote: Hi slight modification of your function can be probably even quicker: fff-function(x) sum(2^(which(rev(x))-1)) :-) Petr Yes, your function is slightly but consistently faster than my suggestion. But my tests show still Bert Gunter's

Re: [R] convert to binary to decimal

2007-02-16 Thread Jim Regetz
Roland Rau wrote: On 2/16/07, Petr Pikal [EMAIL PROTECTED] wrote: Hi slight modification of your function can be probably even quicker: fff-function(x) sum(2^(which(rev(x))-1)) :-) Petr Yes, your function is slightly but consistently faster than my suggestion. But my tests show still

[R] convert to binary to decimal

2007-02-15 Thread Martin Feldkircher
Hello, we need to convert a logical vector to a (decimal) integer. Example: a=c(TRUE, FALSE, TRUE) (binary number 101) the function we are looking for should return dec2bin(a)=5 Is there a package for such a function or is it even implemented in the base package? We found the hexmode and

Re: [R] convert to binary to decimal

2007-02-15 Thread Marc Schwartz
On Thu, 2007-02-15 at 16:38 +0100, Martin Feldkircher wrote: Hello, we need to convert a logical vector to a (decimal) integer. Example: a=c(TRUE, FALSE, TRUE) (binary number 101) the function we are looking for should return dec2bin(a)=5 Is there a package for such a function or is

Re: [R] convert to binary to decimal

2007-02-15 Thread Roland Rau
That was a nice quick distraction. Unfortunately, I am not the first to answer. :-( Anyway, I offer two solutions (which are different from the one of Marc Schwartz); I wrote it quickly but I hope they are correct. Enjoy and thanks, Roland a - c(TRUE, FALSE, TRUE) b - c(TRUE, FALSE, TRUE, TRUE)

Re: [R] convert to binary to decimal

2007-02-15 Thread Bert Gunter
: Thursday, February 15, 2007 8:22 AM To: [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Subject: Re: [R] convert to binary to decimal That was a nice quick distraction. Unfortunately, I am not the first to answer. :-( Anyway, I offer two solutions (which are different from the one of Marc Schwartz

Re: [R] convert to binary to decimal

2007-02-15 Thread Roland Rau
Subject: Re: [R] convert to binary to decimal That was a nice quick distraction. Unfortunately, I am not the first to answer. :-( Anyway, I offer two solutions (which are different from the one of Marc Schwartz); I wrote it quickly but I hope they are correct. Enjoy and thanks, Roland

Re: [R] convert to binary to decimal

2007-02-15 Thread Marc Schwartz
, February 15, 2007 8:22 AM To: [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Subject: Re: [R] convert to binary to decimal That was a nice quick distraction. Unfortunately, I am not the first to answer. :-( Anyway, I offer two

Re: [R] convert to binary to decimal

2007-02-15 Thread Petr Pikal
] To: Bert Gunter [EMAIL PROTECTED] Copies to: [EMAIL PROTECTED], r-help@stat.math.ethz.ch Subject:Re: [R] convert to binary to decimal Hi Bert, First, I was very happy with my solution, but you win (see below)! Best, Roland bert.gunter - function(x