Re: [R] Chars as numbers

From: Josef Eschgfaeller <>
Date: Sat 28 May 2005 - 01:05:13 EST

> as.numeric

Some weeks ago one discussed on the list about how to transform a hexadecimal representation to decimal digits. Specifically one has to transform 'a' to 10 etc. In C one does this with 'a'-87, but I did not find a function for this in R. Using match on letterdigits as in the following is of course a little slow when repeated often.

Hex = function (rep16)
v=sapply(u,function (x)


Horner = function (v,alfa=2)
{b=v[1]; m=length(v)
if (m>1) for (i in 2:m)
b=b*alfa+v[i]; b}

# Example:
for (x in c('0','a0','10e','f0ae'))

# 0
# 160
# 270
# 61614

Josef Eschgfäller
Josef Eschgfäller
Dipartimento Matematico
Universita' di Ferrara

______________________________________________ mailing list PLEASE do read the posting guide!

Received on Sat May 28 01:30:13 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:13 EST