Okay, Bill smelt something wrong, so I must revise. This works for large numbers:
prds = sapply(sapply(cnt_str,charToRaw),as.integer) PS - this also solves an issue I've been having elsewhere... PPS- Bill - I'm reading binary files...and learning. thanks! ben On Fri, Jun 8, 2012 at 12:16 PM, William Dunlap <wdun...@tibco.com> wrote: > Can you tell us why you are interested in this mapping? > I.e., how did the "\001" and "\102" arise and why do you > want to convert them to the integers 1 and 102? > > Bill Dunlap > Spotfire, TIBCO Software > wdunlap tibco.com > > > > -----Original Message----- > > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf > > Of Ben quant > > Sent: Friday, June 08, 2012 11:00 AM > > To: Duncan Murdoch > > Cc: r-help@r-project.org > > Subject: Re: [R] remove leading slash > > > > Thanks for all your help. I did it this way: > > > > > x = sapply(cnt_str,deparse) > > > x > > \002 \001 \002 > > "\"\\002\"" "\"\\001\"" "\"\\102\"" > > > as.numeric(substr(x,3,5)) > > [1] 2 1 102 > > > > ...which is a bit of a hack, but gets me where I want to go. > > > > Thanks, > > Ben > > > > On Fri, Jun 8, 2012 at 11:56 AM, Duncan Murdoch < > murdoch.dun...@gmail.com>wrote: > > > > > On 08/06/2012 1:50 PM, Peter Langfelder wrote: > > > > > >> On Fri, Jun 8, 2012 at 10:25 AM, David > > Winsemius<dwinsemius@comcast.**net<dwinsem...@comcast.net>> > > >> wrote: > > >> > > > >> > On Jun 8, 2012, at 1:11 PM, Ben quant wrote: > > >> > > > >> >> Hello, > > >> >> > > >> >> How do I change this: > > >> >>> > > >> >>> cnt_str > > >> >> > > >> >> [1] "\002" "\001" "\102" > > >> >> > > >> >> ...to this: > > >> >>> > > >> >>> cnt_str > > >> >> > > >> >> [1] "2" "1" "102" > > >> >> > > >> >> Having trouble because of this: > > >> >>> > > >> >>> nchar(cnt_str[1]) > > >> >> > > >> >> [1] 1 > > >> > > > >> > > > >> > "\001" is ASCII cntrl-A, a single character. > > >> > > > >> > ?Quotes # not the first, second or third place I looked but I > knew I > > >> had > > >> > seen it before. > > >> > > >> If you still want to obtain the actual codes, you will be able to get > > >> the number using utf8ToInt from package base or AsciiToInt from > > >> package sfsmisc. By default, the integer codes will be printed in base > > >> 10, though. > > >> > > > > > > You could use > > > > > > > as.octmode(as.integer(**charToRaw("\102"))) > > > [1] "102" > > > > > > if you really want the octal versions. Doesn't work so well on "\1022" > > > though (because that's two characters long). > > > > > > Duncan Murdoch > > > > > > > > >> A roundabout way, assuming your are on a *nix system, would be to > > >> dump() cnt_str into a file, say tmp.txt, then run in a shell (or using > > >> system() ) something like > > >> > > >> sed --in-place 's/\\//g' tmp.txt > > >> > > >> to remove the slashes, then use > > >> > > >> cnt_str_new = read.table("tmp.txt") > > >> > > >> in R to get the codes back in. I'll let you iron out the details. > > >> > > >> Peter > > >> > > >> ______________________________**________________ > > >> R-help@r-project.org mailing list > > >> https://stat.ethz.ch/mailman/**listinfo/r- > > help<https://stat.ethz.ch/mailman/listinfo/r-help> > > >> PLEASE do read the posting guide http://www.R-project.org/** > > >> posting-guide.html <http://www.R-project.org/posting-guide.html> > > >> and provide commented, minimal, self-contained, reproducible code. > > >> > > > > > > ______________________________**________________ > > > R-help@r-project.org mailing list > > > https://stat.ethz.ch/mailman/**listinfo/r-help< > https://stat.ethz.ch/mailman/listinfo/r- > > help> > > > PLEASE do read the posting guide http://www.R-project.org/** > > > posting-guide.html <http://www.R-project.org/posting-guide.html> > > > and provide commented, minimal, self-contained, reproducible code. > > > > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.