[R] Hashing a set

Hans W Borchers hwborchers at googlemail.com
Thu Sep 30 09:48:38 CEST 2010


Lorenzo Isella <lorenzo.isella <at> gmail.com> writes:

> 
> Dear All,
> I am given a time series such at, at every time t_i, I am given a set
> of data (every element of the set is just an integer number).
> What I need is an injective function able to map every set into a
> number (possibly an integer number, but that is not engraved in the
> stone). Does anybody know how to achieve that?

In set theory you learn about the function that assigns to a set of integers
(i1, ..., in) the integer p1^i1 * ... * pn^in, where p1, ... is the sequence
of primes. In practice, unfortunately, this will lead to too large numbers.

I would recommend the 'digest' package that provides hashing functions such
as 'md5', etc., thanks to Dirk Eddelbuettel. It is injective enough and 
returns character strings of fixed length.

Hans Werner

> Cheers
> 
> Lorenzo
>



More information about the R-help mailing list