[R] ASCII characters: from decimal code to R octal?

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Mon Feb 4 13:57:35 CET 2002


David Firth <david.firth at nuffield.oxford.ac.uk> writes:

> Is there a straightforward way to convert character information from
> decimal representation to the octal one used by R?
> 
> I'd like something like a function ascii(number,base=10), such that
> 
> >  ascii(91)
> [1] "\133"
> 
> I can easily do the mapping from 91 to 133, but what is a good way to
> operate on  133 to deliver "\133"?
> 
> Would a lookup table be a better solution?

Stuff like this can do it:

ascii <- sapply(1:127,function(i)
   parse(text=paste("\"\\",structure(i,class="octmode"),"\"",sep=""))[[1]])
ascii[91]

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list