[R] converting string vector to integer/numeric vector

David Winsemius dwinsemius at comcast.net
Sun Sep 5 15:14:32 CEST 2010


On Sep 5, 2010, at 8:48 AM, rajesh j wrote:

> Hi,
>
> Is it possible to convert a string vector to integer or numeric  
> vector? In
> my situation I receive data in a string vector and have to convert  
> it based
> on a given type.

Can you give an example? I don't understand either what sort of  
conversion you desire or what you mean by "convert it based on a given  
type."

There are a couple of function you may want to consider but I am  
having difficulty convincing myself they answer the problem posed:

?charToRaw
?stroi

 > strtoi(charToRaw("123 this is a string"), base=16)   # convert to  
decimal ASCII
  [1]  49  50  51  32 116 104 105 115  32 105 115  32  97  32 115 116  
114 105 110 103

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list